将 .ui 文件导入 Qt5 C++时出错"was not declared in this scope"
Error "was not declared in this scope" when importing .ui file into Qt5 C++
我遇到错误"未在此范围内声明"时,将Qt Wizard从Qt Designer导入Qt C++应用程序。
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
源代码中的所有文件(我只保留重要的文件进行调试(:https://drive.google.com/open?id=1rR4H9Na3bCvdyREn_GZjoDUs9lc3ieYi
编译器输出:
...
/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;
在你的头文件中,#ifdef NEW_CONFERENCE_WIZARD_H
应该是相反的条件:
#ifndef NEW_CONFERENCE_WIZARD_H
对于您的拼写错误,文件内容永远不会包含在编译中,因此main.c
那里没有声明。
相关文章:
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 删除分配的 (?) 指针时"Pointer being freed was not allocated"
- 类中的数组变量C++导致"was not declared in this scope"实现文件的一个函数中错误,但在构造函数中不会导致错误
- 如何解决"cout was not declared in this scope"错误?
- 为什么程序显示我"was not declared in this scope"?
- 为什么我会收到"getuid was not declared in that scope"错误?
- 为什么我会收到此警告? "Member 'x' was not initialized in this constructor"
- 即使包含 <time.h 后仍"‘CLOCK_PER_SEC’ was not declared in this scope"错误>
- 我正在接受"Error: string was not declared in this scope"
- C++编译错误,"malloc: *** error for object: pointer being freed was not allocated"
- 创建一个移动分配函数,不断得到"pointer being freed was not allocated"
- C++ 我一直在"was not declared in this scope error"
- NDK r16b 独立工具链错误:"/usr/bin/ld: this linker was not configured to use sysroots"
- assimp-vc140-mt.dll ASSIMP was not found
- 将 .ui 文件导入 Qt5 C++时出错"was not declared in this scope"
- 如何从类调用函数 - 错误"was not in the scope"
- 编译 CPP 应用程序时出错。 "error: 'posix_memalign' was not declared in this scope"
- libcurl-x64.dll was not found
- 解析 csv 文件,"malloc: *** error for object 0x7ffeeb4f4b80: pointer being freed was not allocated"出现此错误
- C++ "pointer being freed was not allocated"