按照《C++ GUI Qt4编程》做那个对话框程序结果出错,用的是Qt Creator,
- C/C++ code
#include <QApplication>#include <QDialog>#include"ui_gotocelldialog.h"int main(int argc,char *argv[]){ QApplication app(argc,argv); Ui::GoToCellDialog ui; QDialog *dialog=new QDialog; ui.setupUi(dialog); dialog->show(); return app.exec();}
ui_gotocelldialog.h是自动生成的,代码为:
- C/C++ code
#ifndef UI_GOTOCELLDIALOG_H#define UI_GOTOCELLDIALOG_H#include <QtCore/QVariant>#include <QtGui/QAction>#include <QtGui/QApplication>#include <QtGui/QButtonGroup>#include <QtGui/QDockWidget>#include <QtGui/QHBoxLayout>#include <QtGui/QHeaderView>#include <QtGui/QLabel>#include <QtGui/QLineEdit>#include <QtGui/QPushButton>#include <QtGui/QSpacerItem>#include <QtGui/QVBoxLayout>#include <QtGui/QWidget>QT_BEGIN_NAMESPACEclass Ui_GoToCellDialog{public: QWidget *dockWidgetContents; QVBoxLayout *verticalLayout; QHBoxLayout *horizontalLayout; QLabel *label; QLineEdit *lineEdit; QHBoxLayout *horizontalLayout_2; QSpacerItem *horizontalSpacer; QPushButton *pushButton; QPushButton *pushButton_2; void setupUi(QDockWidget *GoToCellDialog) { …… } // setupUi void retranslateUi(QDockWidget *GoToCellDialog) { GoToCellDialog->setWindowTitle(QApplication::translate("GoToCellDialog", "GoToCell", 0, QApplication::UnicodeUTF8)); label->setText(QApplication::translate("GoToCellDialog", "&Cell", 0, QApplication::UnicodeUTF8)); pushButton->setText(QApplication::translate("GoToCellDialog", "OK", 0, QApplication::UnicodeUTF8)); pushButton_2->setText(QApplication::translate("GoToCellDialog", "Cancel", 0, QApplication::UnicodeUTF8)); } // retranslateUi};namespace Ui { class GoToCellDialog: public Ui_GoToCellDialog {};} // namespace UiQT_END_NAMESPACE#endif // UI_GOTOCELLDIALOG_H
错误信息为
E:\Qt\Dialog\QtDialog.cpp:-1: In function 'int qMain(int, char**)':
E:\Qt\Dialog\QtDialog.cpp:13: 错误:no matching function for call to 'Ui::GoToCellDialog::setupUi(QDialog*&)'
E:\Qt\Dialog\ui_gotocelldialog.h:42: candidates are: void Ui_GoToCellDialog::setupUi(QDockWidget*)
新手求教!
------解决方案--------------------
QDialog *dialog=new QDialog;
类型不匹配,应该是QDockWidget
------解决方案--------------------
请统一到底是setupUi(QDockWidget*)还是setupUi(QDialog*
------解决方案--------------------
dialog不是一个QDockWidget *,setupUi参数类型不对么