Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // mywidget.h
- #ifndef MYWIDGET_H
- #define MYWIDGET_H
- #include <QWidget>
- class MyWidget : public QWidget
- {
- Q_OBJECT
- public:
- explicit MyWidget(QWidget *parent = 0);
- signals:
- public slots:
- };
- #endif // MYWIDGET_H
- //---------------------------------------------------------------------------------------
- // mywidget.cpp
- #include "mywidget.h"
- MyWidget::MyWidget(QWidget *parent) :
- QWidget(parent)
- {
- }
- //---------------------------------------------------------------------------------------
- // mainwindow.h
- #ifndef MAINWINDOW_H
- #define MAINWINDOW_H
- #include <QMainWindow>
- namespace Ui {
- class MainWindow;
- }
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
- public:
- explicit MainWindow(QWidget *parent = 0);
- ~MainWindow();
- private:
- Ui::MainWindow *ui;
- };
- #endif // MAINWINDOW_H
- //---------------------------------------------------------------------------------------
- // mainwindow.cpp
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include "mywidget.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- // QWidget *w = new MyWidget(this); // this line is ok
- MyWidget *w = new MyWidget(this); // but this one is not
- w->setGeometry(10,20,100,100);
- w->setStyleSheet("background-color:white;");
- w->show();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
Advertisement
Add Comment
Please, Sign In to add comment