C++编译Qt for Visual Studio 2017的问题

C++ compile problems with Qt for Visual Studio 2017

本文关键字:2017 问题 Studio Visual 编译 Qt for C++      更新时间:2023-10-16

我已经安装了带有msvc2017_64二进制文件的Qt Creator。我还安装了VS2017的Qt插件。我可以毫无问题地创建一个QtGuiApplication,但是当我尝试编译它时,出现了许多错误。我在这里列出了它们,在 pastebin 上,因为我无法将这么多字符添加到 Stackoverflow 中。对此我很抱歉。

我需要任何必要的软件包吗?我为 VS2017 ofc 安装了C++。我还在Qt VS Tools菜单中加入了QtPath。

我没有编辑文件,因为项目创建和编译由于错误而失败。


编辑:这个问题在这里解决了。但是,不仅存在 Pastebin 形式的错误,QtGuiApplication.h中的错误也存在


QtGuiApplication.h:(错误标记为注释(

#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h" //This could not be found
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui; //Ui namespace does not exist
};

Qt应用.cpp:

#include "stdafx.h"
#include "QtGuiApplication1.h"
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}

主.cpp:

#include "stdafx.h"
#include "QtGuiApplication1.h"
#include <QtWidgets/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QtGuiApplication1 w;
w.show();
return a.exec();
}

我自己解决了这个问题!

Qt插件使用Windowns 8.1 SDK创建项目,您需要将其重新定位到Win 10 SDK才能从QtGuiApplication.h获取编译错误。即使安装了 8.1 SDK。似乎是一个错误。

解决方案对我来说非常简单,只需从解决方案资源管理器卸载然后重新加载解决方案! 这将清除所有 c++ 编译器错误!不知道为什么...