开发者

Some Qt errors - How to solve?

开发者 https://www.devze.com 2023-02-26 14:23 出处:网络
I have the following main.cpp file: #include <QApplication> #include \"ui_checkabder.h\" #include <QDialog>

I have the following main.cpp file:

#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();
}

And, get the following errors when trying to run the program:

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

The contents of ui_checkabder.h is as follows:

/********************************************************************************
** 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;
    Q开发者_JAVA百科HBoxLayout *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

Any ideas on how to solve those problems?

Thanks.


Your class name is Ui_Form and Ui::Form and not CheckAbder. You should rename it in Designer.


You need to understand uic a little bit. File name has nothing to do with generated Ui namespaces content. Your widget in .ui file is named "Form" not CheckAbder. You can solve your problem in two ways:

  1. Start using Ui::Form in your .cpp file
  2. Rename Form to CheckAbder in you .ui file

Also make sure, your .ui file is added to project, so it will automaticly generate new ui_*.h file after you change .ui


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

should be

namespace Ui {
    class CheckAbder: public Ui_Form {};
} // namespace Ui
0

精彩评论

暂无评论...
验证码 换一张
取 消