找不到“ui_mainwindow.h”文件

Ale*_*lex 6 c++ qt qt-creator

我刚刚在 Windows 10 PC 上安装了 Qt。我创建一个新项目,并在 mainwindow.cpp 文件中写入一些行:

#include "mainwindow.h"
#include "ui_mainwindow.h"

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

MainWindow::~MainWindow() {
  delete ui;
}
Run Code Online (Sandbox Code Playgroud)

但 Qt 环境在某些行上给了我错误:

mainwindow.cpp: 2: 10: error: 'ui_mainwindow.h' file not found
mainwindow.cpp: 4:24: error: unknown type name 'QWidget'
mainwindow.cpp: 6: 12: error: allocation of incomplete type 'Ui :: MainWindow'
mainwindow.h: 7: 7: note: forward declaration of 'Ui :: MainWindow'
mainwindow.cpp: 8: 7: error: member access into incomplete type 'Ui :: MainWindow'
mainwindow.h: 7: 7: note: forward declaration of 'Ui :: MainWindow'
Run Code Online (Sandbox Code Playgroud)

编译时:

Cannot run complier 'clang ++'
Run Code Online (Sandbox Code Playgroud)

我该如何解决这些问题?如何以及在哪里安装 clang++?

小智 1

您需要更改构建目录。Settings -> under "Deskstop Qt...." build ->那么如果你有错误的构建目录(如果它是错误的,它会是红色的)。你需要改变它。

新的构建目录必须是您刚刚创建 Qt 项目时保存该项目的文件夹。