Lỗi was not declared in this scope khi import file .ui vào Qt5 C++

Chào mọi người.

Em đang làm Qt5 C++ và gặp phải vấn đề không compile được khi import và chạy Wizard từ Qt Designer (file *.ui).

Source code file main:

src/main.cpp

#include <QApplication>
#include <stdlib.h>
#include <iostream>
#include "new_conference_wizard.h"


int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

    NewConferenceWizard *conf = new NewConferenceWizard;
    conf->show();

    return a.exec();
}

src/new_conference_wizard.cpp

#include "new_conference_wizard.h"

NewConferenceWizard::NewConferenceWizard(QWidget *parent) : QMainWindow(parent), ui(new Ui::NewConferenceWizard) {
    ui->setupUi(this);
    
}

NewConferenceWizard::~NewConferenceWizard()
{
    delete ui;
}

src/new_conference_wizard.h

#ifdef NEW_CONFERENCE_WIZARD_H
#define NEW_CONFERENCE_WIZARD_H

#include <QWizard>
#include "ui_new_conference_wizard.h"
 
namespace Ui {
class NewConferenceWizard;
}
 
class NewConferenceWizard : public QWizard
{
    Q_OBJECT
 
public:
    explicit NewConferenceWizard(QWidget *parent = 0);
    ~NewConferenceWizard();
 
private:
    Ui::Widget *ui;
};


#endif

Lỗi gặp phải:

/mnt/DATA/Sync2/WorkData/HUST2019/Projects/NetworkAndMedia/Project/desktop-app/src/main.cpp: In function ‘int main(int, char**)’:
/mnt/DATA/Sync2/WorkData/HUST2019/Projects/NetworkAndMedia/Project/desktop-app/src/main.cpp:36:5: error: ‘NewConferenceWizard’ was not declared in this scope
     NewConferenceWizard *conf = new NewConferenceWizard;
     ^~~~~~~~~~~~~~~~~~~
/mnt/DATA/Sync2/WorkData/HUST2019/Projects/NetworkAndMedia/Project/desktop-app/src/main.cpp:36:26: error: ‘conf’ was not declared in this scope
     NewConferenceWizard *conf = new NewConferenceWizard;
                          ^~~~
/mnt/DATA/Sync2/WorkData/HUST2019/Projects/NetworkAndMedia/Project/desktop-app/src/main.cpp:36:26: note: suggested alternative: ‘cosf’
     NewConferenceWizard *conf = new NewConferenceWizard;
                          ^~~~
                          cosf
/mnt/DATA/Sync2/WorkData/HUST2019/Projects/NetworkAndMedia/Project/desktop-app/src/main.cpp:36:37: error: ‘NewConferenceWizard’ does not name a type
     NewConferenceWizard *conf = new NewConferenceWizard;

Toàn bộ source để compile em xin up ở đây: https://drive.google.com/open?id=1rR4H9Na3bCvdyREn_GZjoDUs9lc3ieYi

Em tìm chưa ra lỗi. Rất mong mọi người giúp đỡ.

Em đã tìm thấy vấn đề mọi người nhé. #ifdef NEW_CONFERENCE_WIZARD_H bị viết sai. Lẽ ra phải là #ifndef NEW_CONFERENCE_WIZARD_H.

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?