-
UID:45472
-
- 注册时间2008-06-02
- 最后登录2012-10-10
- 在线时间31小时
-
- 发帖35
- 搜Ta的帖子
- 精华0
- 金钱495
- 威望38
- 贡献值0
- 好评度37
-
访问TA的空间加好友用道具
|
程序目标: 主界面:一个dialog的主窗口,里面带有一个“创建”的按钮 功能:点击“创建“之后,能够在dialog内创建一个LCD Number控件和Dial控件,且两个控件同时显示一个随机数 我的程序make之后出现以下错误 moc_testdialog.cpp: 43 : error: 'staticMetaObject' is not a member of 'Ui_TestUI' moc_testdialog.cpp:In member function 'virtual void* TestDialog::qt_metacast(const
char *)': moc_testdialog.cpp: 59 : error: 'qt_metacast' is not a member of 'Ui_TestUI' moc_testdialog.cpp: In member function 'virtual int TestDialog::qt_metacall
(QMetaObject::Call,int,void**)': moc_testdialog.cpp: 64 : error: 'qt_metacall' is not a member of 'Ui_TestUI' 程序代码如下 界面头文件ui_test.h(用designer设计界面,然后用uic工具产生的头文件) - #ifndef UI_TEST_H
- #define UI_TEST_H
- #include <QtCore/QVariant>
- #include <QtGui/QAction>
- #include <QtGui/QApplication>
- #include <QtGui/QButtonGroup>
- #include <QtGui/QDialog>
- #include <QtGui/QHeaderView>
- #include <QtGui/QPushButton>
- QT_BEGIN_NAMESPACE
- class Ui_TestUI
- {
- public:
- QPushButton *creatButton;
- void setupUi(QDialog *TestUI)
- {
- if (TestUI->objectName().isEmpty())
- TestUI->setObjectName(QString::fromUtf8("TestUI"));
- TestUI->resize(294, 452);
- creatButton = new QPushButton(TestUI);
- creatButton->setObjectName(QString::fromUtf8("creatButton"));
- creatButton->setGeometry(QRect(110, 410, 75, 23));
- retranslateUi(TestUI);
- QMetaObject::connectSlotsByName(TestUI);
- } // setupUi
- void retranslateUi(QDialog *TestUI)
- {
- TestUI->setWindowTitle(QApplication::translate("TestUI", "Test", 0, QApplication::UnicodeUTF8));
- creatButton->setText(QApplication::translate("TestUI", "\345\210\233\345\273\272", 0, QApplication::UnicodeUTF8));
- Q_UNUSED(TestUI);
- } // retranslateUi
- };
- namespace Ui {
- class TestUI: public Ui_TestUI {};
- } // namespace Ui
- QT_END_NAMESPACE
- #endif // UI_TEST_H
调用界面头文件的类的头文件和实现文件 - #ifndef __TESTDIALOG_H__
- #define __TESTDIALOG_H__
- #include <QDialog>
- #include <QDial>
- #include <QLCDNumber>
- #include <QTimer>
- #include "ui_test.h"
- class TestDialog:public Ui_TestUI,public QDialog
- {
- Q_OBJECT
- public:
- TestDialog(QDialog *dlg=0);
- ~TestDialog(){}
- private slots:
- void AddControls();
- void TimerEvent();
- protected:
- QDial *dial;
- QLCDNumber *lcd;
- QTimer *timer;
- };
- #endif
- #include "testdialog.h"
- TestDialog::TestDialog(QDialog *dlg)
- {
- setupUi(this);
- timer = new QTimer(this);
- QObject::connect( timer, SIGNAL(timeout()), this, SLOT(TimerEvent()));
- QObject::connect( creatButton, SIGNAL(clicked()), this, SLOT(AddControls()));
-
- }
- void TestDialog::AddControls()
- {
- //creat lcd control
- lcd = new QLCDNumber(this);
- lcd->setObjectName(QString::fromUtf8("lcd"));
- lcd->setGeometry(QRect(50, 40, 221, 121));
-
- //creat dial control
- dial = new QDial(this);
- dial->setObjectName(QString::fromUtf8("dial"));
- dial->setGeometry(QRect(50, 180, 221, 181));
- dial->setRange(0, 100);
- timer->start(1000);
- }
- void TestDialog::TimerEvent()
- {
- int data = rand()%101;//0~100
- lcd->display(data);
- dial->setValue(data);
- }
main函数代码 - #include <QApplication>
- #include "testdialog.h"
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- TestDialog dialog;
- dialog.show();
- return app.exec();
- }
个人不知道错在哪里。望高手赐教
|