c++ - 在 VS 上使用 Qt 库

标签 c++ visual-studio qt visual-studio-2017

我正在尝试在 VS 上构建一个 C++ 项目。该项目是在 Linux 机器上使用 NetBeans 开发的,现在我在 Windows 上使用 Visual Studio 2017。

它不是使用 Qt Creatos 开发的,所以库是手动添加的,语句如下:

#include <QtCore>
#include <QCoreApplication>
#include <QObject>
#include <QStringList>
#include <QMap>
...

这是我目前所做的:

  • 下载了最新的 Qt 版本
  • 解压 C:\Qt 中的所有内容
  • 在 VS 属性 > VC++ 目录 > 包含目录中 - 我添加了 C:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include 和 C:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore
  • 在 VS 属性 > VC++ 目录 > 库目录中 - 我添加了 C:\Qt\Qt5.9.2\5.9.2\msvc2017_64\lib

但是,当我尝试 #include <QtCore>似乎 VS 期望更多: https://imgur.com/a/ruSbi

但它无法编译。

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E0020   identifier "QEvent" is undefined        c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qabstractanimation.h 121 
Error (active)  E0020   identifier "QEvent" is undefined    c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qabstractstate.h 73  
Error (active)  E0020   identifier "QEvent" is undefined    c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qabstractstate.h 74  
Error (active)  E0020   identifier "QEvent" is undefined    c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qabstractstate.h 76  
Error (active)  E1455   member function declared with 'override' does not override a base class member      c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qabstracttransition.h    105 
Error (active)  E1455   member function declared with 'override' does not override a base class member  c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qanimationgroup.h    70  
Error (active)  E1455   member function declared with 'override' does not override a base class member  c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qcoreapplication.h   190 
Error (active)  E0020   identifier "qint8" is undefined c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qdatastream.h    147 
Error (active)  E0020   identifier "qint8" is undefined c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qdatastream.h    163 
Error (active)  E0260   explicit type is missing ('int' assumed)    c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qendian.h    236 
Error (active)  E0801   "qint8" is not a class or function template name in the current scope   c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qendian.h    236 
Error (active)  E0065   expected a ';'  c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qendian.h    236 
Error (active)  E0020   identifier "qint8" is undefined c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qendian.h    236 
Error (active)  E0020   identifier "QEvent" is undefined    c:\Qt\Qt5.9.2\5.9.2\msvc2017_64\include\QtCore\qeventloop.h 79  
Error (active)  E1455   member function declared with 'override' does not override a base class member
...     

所以,我想我漏掉了什么。我是 VS 的新手,所以我很感激任何帮助。

谢谢

最佳答案

QtCore既是一个目录又是一个包含文件:

Directory: <Qt_Install_Path>/include/QtCore
File:      <Qt_Install_Path>/include/QtCore/QtCore

您还需要在每个包含 Q_OBJECT 宏的 header 上运行 Qt mocmoc 将生成额外的 C++ 文件,您需要对其进行编译。使用 qmakecmake 等工具时,它非常简单。对于 VS,您可能想使用 Qt Visual Studio Add-in .

关于c++ - 在 VS 上使用 Qt 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47324863/

相关文章:

c++ - FlannBasedMatcher 返回不同的结果

sql-server - ConnectionString 未在 SSIS 集成项目中加密

Qt:QMediaPlayer 停止后的 Action

c++ - 创建监听 QLabel

c++ - 在 Linux 上从 C++ 调用可执行文件,并等待它完成

c++ - 如何选择部分模板特化?

c++ - 在 QFileDialog 中禁用文件名框

c# - 如何在 VS 2017 for ASP.NET Core 项目中按路径段嵌套文件

asp.net - 如何在 Visual Studio 2010 中设置 Umbraco cms?

c++ - Qt 线程计算输出到 GUI 中的自己的小部件?