• 5827阅读
  • 4回复

一个简单的小程序 编译通不过 望高手指教 [复制链接]

上一主题 下一主题
离线花布鱼
 
只看楼主 倒序阅读 楼主  发表于: 2009-10-15
程序目标:
主界面:一个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工具产生的头文件)
  1. #ifndef UI_TEST_H
  2. #define UI_TEST_H
  3. #include <QtCore/QVariant>
  4. #include <QtGui/QAction>
  5. #include <QtGui/QApplication>
  6. #include <QtGui/QButtonGroup>
  7. #include <QtGui/QDialog>
  8. #include <QtGui/QHeaderView>
  9. #include <QtGui/QPushButton>
  10. QT_BEGIN_NAMESPACE
  11. class Ui_TestUI
  12. {
  13. public:
  14.     QPushButton *creatButton;
  15.     void setupUi(QDialog *TestUI)
  16.     {
  17.         if (TestUI->objectName().isEmpty())
  18.             TestUI->setObjectName(QString::fromUtf8("TestUI"));
  19.         TestUI->resize(294, 452);
  20.         creatButton = new QPushButton(TestUI);
  21.         creatButton->setObjectName(QString::fromUtf8("creatButton"));
  22.         creatButton->setGeometry(QRect(110, 410, 75, 23));
  23.         retranslateUi(TestUI);
  24.         QMetaObject::connectSlotsByName(TestUI);
  25.     } // setupUi
  26.     void retranslateUi(QDialog *TestUI)
  27.     {
  28.         TestUI->setWindowTitle(QApplication::translate("TestUI", "Test", 0, QApplication::UnicodeUTF8));
  29.         creatButton->setText(QApplication::translate("TestUI", "\345\210\233\345\273\272", 0, QApplication::UnicodeUTF8));
  30.         Q_UNUSED(TestUI);
  31.     } // retranslateUi
  32. };
  33. namespace Ui {
  34.     class TestUI: public Ui_TestUI {};
  35. } // namespace Ui
  36. QT_END_NAMESPACE
  37. #endif // UI_TEST_H

调用界面头文件的类的头文件和实现文件
  1. #ifndef __TESTDIALOG_H__
  2. #define __TESTDIALOG_H__
  3. #include <QDialog>
  4. #include <QDial>
  5. #include <QLCDNumber>
  6. #include <QTimer>
  7. #include "ui_test.h"
  8. class TestDialog:public Ui_TestUI,public QDialog
  9. {
  10.     Q_OBJECT
  11. public:
  12.     TestDialog(QDialog *dlg=0);
  13.     ~TestDialog(){}
  14. private slots:
  15.     void AddControls();
  16.     void TimerEvent();
  17. protected:
  18.     QDial *dial;
  19.     QLCDNumber *lcd;
  20.     QTimer *timer;
  21. };
  22. #endif


  1. #include "testdialog.h"
  2. TestDialog::TestDialog(QDialog *dlg)
  3. {
  4.     setupUi(this);
  5.     timer = new QTimer(this);
  6.     QObject::connect( timer, SIGNAL(timeout()), this, SLOT(TimerEvent()));
  7.     QObject::connect( creatButton, SIGNAL(clicked()), this, SLOT(AddControls()));
  8.     
  9. }
  10. void TestDialog::AddControls()
  11. {
  12.     //creat lcd control
  13.     lcd = new QLCDNumber(this);
  14.     lcd->setObjectName(QString::fromUtf8("lcd"));
  15.     lcd->setGeometry(QRect(50, 40, 221, 121));
  16.     
  17.     //creat dial control
  18.     dial = new QDial(this);
  19.     dial->setObjectName(QString::fromUtf8("dial"));
  20.     dial->setGeometry(QRect(50, 180, 221, 181));
  21.     dial->setRange(0, 100);
  22.     timer->start(1000);
  23. }
  24. void TestDialog::TimerEvent()
  25. {
  26.     int data = rand()%101;//0~100
  27.     lcd->display(data);
  28.     dial->setValue(data);
  29. }


main函数代码
  1. #include <QApplication>
  2. #include "testdialog.h"
  3. int main(int argc, char *argv[])
  4. {
  5.     QApplication app(argc, argv);
  6.     TestDialog dialog;
  7.     dialog.show();
  8.     return app.exec();
  9. }


个人不知道错在哪里。望高手赐教
离线foxyz

只看该作者 1楼 发表于: 2009-10-15
建议把moc_*.cpp删除掉,重新生成一下!
我不清楚你的环境,我是solaris的,一般我会make clean,make
离线花布鱼
只看该作者 2楼 发表于: 2009-10-15
引用第1楼foxyz于2009-10-15 10:06发表的  :
建议把moc_*.cpp删除掉,重新生成一下!
我不清楚你的环境,我是solaris的,一般我会make clean,make


我在debian下面 我试过了还是不行 不知道是什么错误
离线dbzhang800

只看该作者 3楼 发表于: 2009-10-15
class TestDialog:public Ui_TestUI,public QDialog

改成

class TestDialog:public QDialog, public Ui_TestUI

试试
离线花布鱼
只看该作者 4楼 发表于: 2009-10-15
引用第3楼dbzhang800于2009-10-15 10:32发表的  :
class TestDialog:public Ui_TestUI,public QDialog
改成
class TestDialog:public QDialog, public Ui_TestUI
.......



是这个错误 谢谢你^^
快速回复
限100 字节
 
上一个 下一个