2011-04-19 54 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