2011-04-19 58 views
-1

我有以下main.cpp文件:一些Qt错误 - 如何解决?

#include <QApplication> 
#include "ui_checkabder.h" 
#include <QDialog> 
int main(int argc, char *argv[]) 
{ 
QApplication app(argc, argv); 
Ui::CheckAbder ui; 
QDialog *dialog = new QDialog; 
ui.setupUi(dialog); 
dialog->show(); 
return app.exec(); 
} 

而且,试图运行该程序时,遇到下列错误:如下

C:/Users/avbder/Desktop/abder/main.cpp:7: error: 'CheckAbder' is not a member of 'Ui' 

C:/Users/avbder/Desktop/abder/main.cpp:7: error: expected ';' before 'ui' 

C:/Users/avbder/Desktop/abder/main.cpp:7: error: expected ';' before 'ui' 

C:/Users/avbder/Desktop/abder/main.cpp:9: error: 'ui' was not declared in this scope 

ui_checkabder.h内容是:

/******************************************************************************** 
** Form generated from reading UI file 'checkabder.ui' 
** 
** Created: Mon Apr 18 10:01:09 2011 
**  by: Qt User Interface Compiler version 4.7.3 
** 
** WARNING! All changes made in this file will be lost when recompiling UI file! 
********************************************************************************/ 

#ifndef UI_CHECKABDER_H 
#define UI_CHECKABDER_H 

#include <QtCore/QVariant> 
#include <QtGui/QAction> 
#include <QtGui/QApplication> 
#include <QtGui/QButtonGroup> 
#include <QtGui/QHBoxLayout> 
#include <QtGui/QHeaderView> 
#include <QtGui/QLabel> 
#include <QtGui/QLineEdit> 
#include <QtGui/QPushButton> 
#include <QtGui/QVBoxLayout> 
#include <QtGui/QWidget> 

QT_BEGIN_NAMESPACE 

class Ui_Form 
{ 
public: 
    QVBoxLayout *verticalLayout; 
    QHBoxLayout *horizontalLayout; 
    QLabel *label; 
    QLineEdit *lineEdit; 
    QHBoxLayout *horizontalLayout_2; 
    QPushButton *okButton; 
    QPushButton *cancelButton; 

    void setupUi(QWidget *Form) 
    { 
     if (Form->objectName().isEmpty()) 
      Form->setObjectName(QString::fromUtf8("Form")); 
     Form->resize(400, 300); 
     verticalLayout = new QVBoxLayout(Form); 
     verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); 
     horizontalLayout = new QHBoxLayout(); 
     horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); 
     label = new QLabel(Form); 
     label->setObjectName(QString::fromUtf8("label")); 
     QFont font; 
     font.setFamily(QString::fromUtf8("Comic Sans MS")); 
     font.setPointSize(16); 
     label->setFont(font); 

     horizontalLayout->addWidget(label); 

     lineEdit = new QLineEdit(Form); 
     lineEdit->setObjectName(QString::fromUtf8("lineEdit")); 

     horizontalLayout->addWidget(lineEdit); 


     verticalLayout->addLayout(horizontalLayout); 

     horizontalLayout_2 = new QHBoxLayout(); 
     horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); 
     okButton = new QPushButton(Form); 
     okButton->setObjectName(QString::fromUtf8("okButton")); 
     okButton->setEnabled(false); 
     QFont font1; 
     font1.setFamily(QString::fromUtf8("Comic Sans MS")); 
     font1.setBold(true); 
     font1.setWeight(75); 
     okButton->setFont(font1); 

     horizontalLayout_2->addWidget(okButton); 

     cancelButton = new QPushButton(Form); 
     cancelButton->setObjectName(QString::fromUtf8("cancelButton")); 
     cancelButton->setFont(font1); 

     horizontalLayout_2->addWidget(cancelButton); 


     verticalLayout->addLayout(horizontalLayout_2); 


     retranslateUi(Form); 

     QMetaObject::connectSlotsByName(Form); 
    } // setupUi 

    void retranslateUi(QWidget *Form) 
    { 
     Form->setWindowTitle(QApplication::translate("Form", "Form", 0, QApplication::UnicodeUTF8)); 
     label->setText(QApplication::translate("Form", "Name", 0, QApplication::UnicodeUTF8)); 
     okButton->setText(QApplication::translate("Form", "OK", 0, QApplication::UnicodeUTF8)); 
     cancelButton->setText(QApplication::translate("Form", "CANCEL", 0, QApplication::UnicodeUTF8)); 
    } // retranslateUi 

}; 

namespace Ui { 
    class Form: public Ui_Form {}; 
} // namespace Ui 

QT_END_NAMESPACE 

#endif // UI_CHECKABDER_H 

关于如何解决这些问题的任何想法?

谢谢。

+0

ui_checkabder.h文件包含什么? – 2011-04-19 10:31:00

+0

@Kamil Klimek。感谢您的回复。我在我的原始帖子中包含了'ui_checkabder.h' – Simplicity 2011-04-19 10:39:12

回答

1

您的分类名称是Ui_FormUi::Form而不是CheckAbder。你应该在Designer中重命名它。

+0

感谢您的回复。由于我刚接触'Qt',你能否进一步解释它? – Simplicity 2011-04-19 10:54:02

+0

只需使用Qt Designer编辑checkabder.ui文件,在对象树中选择根元素(第一个),并将其对象名称更改为CheckAbder – 2011-04-20 07:46:52

1

你需要了解一点点。文件名与生成的Ui命名空间内容无关。 .ui文件中的小部件名为“Form”而非CheckAbder。使用UI ::形式在您的.cpp文件

  • 重命名表

    1. 开始到CheckAbder在你的.ui文件

    还要确保,您:您可以通过两种方式解决你的问题。更改后的UI文件添加到项目中,所以它将会被自动生成新的用户界面_ * .h文件的.ui

  • -4
    namespace Ui { 
        class Form: public Ui_Form {}; 
    } // namespace Ui 
    

    应该

    namespace Ui { 
        class CheckAbder: public Ui_Form {}; 
    } // namespace Ui 
    
    +1

    Ofcourse,应该是。但请记住,ui_checkabder.h是生成的头文件,只要在.ui文件中进行更改就会更改。 – 2011-04-19 11:50:31

    +0

    那么在这种情况下,您将使用Ui :: Form而不是Ui :: CheckAbder。 Pfff – 2011-04-19 16:41:54

    +0

    您需要将.ui文件中根对象的对象名称更改为您所需的类名称。生成的头文件然后将使用您想要的名称,而不是默认名称“form” – 2011-04-19 16:56:18