Hi everybody
I have created a widget with the designer. Now i am trying to subclass it like the doc, i get following error by compiling. Can somebody see the problem?
main.cpp
#include <QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
Dialog dialog;
dialog.show();
return app.exec();
}
#include <QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Dialog dialog;
dialog.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
dialog.h
#include "ui_widget1.h"
{
Q_OBJECT
public:
private:
Ui::Dialog ui;
};
#include "ui_widget1.h"
class Dialog : public QDialog
{
Q_OBJECT
public:
Dialog(QWidget *parent = 0);
private:
Ui::Dialog ui;
};
To copy to clipboard, switch view to plain text mode
dialog.cpp
#include "dialog.h"
{
ui.setupUi(this);
}
#include "dialog.h"
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
To copy to clipboard, switch view to plain text mode
ui_widget1.h
#ifndef UI_WIDGET1_H
#define UI_WIDGET1_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Ui_Widget1
{
public:
{
Widget1
->setObjectName
(QString::fromUtf8("Widget1"));
Widget1
->resize
(QSize(181,
101).
expandedTo(Widget1
->minimumSizeHint
()));
btn1
->setObjectName
(QString::fromUtf8("btn1"));
btn1
->setGeometry
(QRect(50,
40,
75,
24));
btn1_2
->setObjectName
(QString::fromUtf8("btn1_2"));
btn1_2
->setGeometry
(QRect(100,
70,
75,
24));
retranslateUi(Widget1);
} // setupUi
void retranslateUi
(QWidget *Widget1
) {
Q_UNUSED(Widget1);
} // retranslateUi
};
namespace Ui {
class Widget1: public Ui_Widget1 {};
} // namespace Ui
#endif // UI_WIDGET1_H
#ifndef UI_WIDGET1_H
#define UI_WIDGET1_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Ui_Widget1
{
public:
QPushButton *btn1;
QPushButton *btn1_2;
void setupUi(QWidget *Widget1)
{
Widget1->setObjectName(QString::fromUtf8("Widget1"));
Widget1->resize(QSize(181, 101).expandedTo(Widget1->minimumSizeHint()));
btn1 = new QPushButton(Widget1);
btn1->setObjectName(QString::fromUtf8("btn1"));
btn1->setGeometry(QRect(50, 40, 75, 24));
btn1_2 = new QPushButton(Widget1);
btn1_2->setObjectName(QString::fromUtf8("btn1_2"));
btn1_2->setGeometry(QRect(100, 70, 75, 24));
retranslateUi(Widget1);
QMetaObject::connectSlotsByName(Widget1);
} // setupUi
void retranslateUi(QWidget *Widget1)
{
Widget1->setWindowTitle(QApplication::translate("Widget1", "Ich bin ein Widget", 0, QApplication::UnicodeUTF8));
btn1->setText(QApplication::translate("Widget1", "Show Message", 0, QApplication::UnicodeUTF8));
btn1_2->setText(QApplication::translate("Widget1", "Show Message", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Widget1);
} // retranslateUi
};
namespace Ui {
class Widget1: public Ui_Widget1 {};
} // namespace Ui
#endif // UI_WIDGET1_H
To copy to clipboard, switch view to plain text mode
ERROR:
dialog.
h:5: error
: invalid use of undefined type `
struct QDialog'D:/apps/Qt/4.1.3/include/QtGui/../../src/gui/kernel/qwindowdefs.h:38: error: for
ward declaration of `struct QDialog'
dialog.h:12: error: using-declaration for non-member at class scope
dialog.h:12: error: expected `;' before "ui"
In file included from dialog.cpp:1:
dialog.h:13:3: warning: no newline at end of file
dialog.cpp: In constructor `Dialog::Dialog(QWidget*)':
dialog.
cpp:4: error
: type `
struct QDialog' is not a direct base of `Dialog'dialog.cpp:6: error: `ui' undeclared (first use this function)
dialog.cpp:6: error: (Each undeclared identifier is reported only once for each
function it appears in.)
dialog.cpp:8:2: warning: no newline at end of file
mingw32-make[1]: *** [release\dialog.o] Error 1
mingw32-make[1]: Leaving directory `W:/Data/qt4/einstieg/widget'
mingw32-make: *** [release] Error 2
dialog.h:5: error: invalid use of undefined type `struct QDialog'
D:/apps/Qt/4.1.3/include/QtGui/../../src/gui/kernel/qwindowdefs.h:38: error: for
ward declaration of `struct QDialog'
dialog.h:12: error: using-declaration for non-member at class scope
dialog.h:12: error: expected `;' before "ui"
In file included from dialog.cpp:1:
dialog.h:13:3: warning: no newline at end of file
dialog.cpp: In constructor `Dialog::Dialog(QWidget*)':
dialog.cpp:4: error: type `struct QDialog' is not a direct base of `Dialog'
dialog.cpp:6: error: `ui' undeclared (first use this function)
dialog.cpp:6: error: (Each undeclared identifier is reported only once for each
function it appears in.)
dialog.cpp:8:2: warning: no newline at end of file
mingw32-make[1]: *** [release\dialog.o] Error 1
mingw32-make[1]: Leaving directory `W:/Data/qt4/einstieg/widget'
mingw32-make: *** [release] Error 2
To copy to clipboard, switch view to plain text mode
Thank you
Bookmarks