使用 Visual Studio 2012/Visual Studio 2013 构建 Qt5,并与 IDE 集成

如何让 Qt5 下载并与 Visual Studio 2012 集成?您会遇到哪些问题,您如何解决这些问题?

How do you get Qt5 to download and integrate with Visual Studio 2012? What are some of the problems you will encounter, and how do you solve those problems?

更新.Visual Studio 2013

也报告了 Visual Studio 2013 的成功,并且正在为 VS 2013 维护注释.

Successes are reported with Visual Studio 2013 as well, and the notes are being maintained for VS 2013.

另请注意,问题的重点主要集中在使用 Visual Studio构建 Qt.还有与Visual Studio IDE集成的注意事项

Also note that the focus of the question is strongly on just building Qt with Visual Studio. There are also notes about integrating with the Visual Studio IDE

推荐答案

此方法经过测试可在 Visual Studio 2013 上运行.使用 Visual Studio 2012 和 2013 的预构建二进制文件可用 此处,包括 OpenGL 版本.

This method is tested to work on Visual Studio 2013. Pre-built binaries using Visual Studio 2012 and 2013 are available here, including OpenGL versions.

  1. 在此处下载并安装 RapidEE.RapidEE 是一个 windows 环境变量编辑器.它对于此过程的其余部分(以及一般情况)非常有用.

  1. Download and install RapidEE here. RapidEE is a windows environment variables editor. It is extremely useful for the rest of this process (and just in general).

安装 DirectX 11 SDK.它现在是 Windows 8 SDK 的一部分,因此您首先必须安装 DirectX 10 SDK,您可以获得 此处(但请参阅下一句中的警告).如果您安装了 Visual C++ 2010 Redistributable Package,并且您可能安装了(它与 VS 2010 一起自动安装),请按照 此处 协助安装 DirectX 10.安装 DirectX 10 SDK 后,下载并安装 Windows 8 SDK 此处,其中包含 DirectX 11 SDK.是的,这很痛苦,但除非您知道自己拥有 DirectX 11 SDK,否则 Qt 构建将失败.

Install the DirectX 11 SDK. It is now part of the Windows 8 SDK, so you first have to install the DirectX 10 SDK, which you can get here (but see warning in next sentence). If you have the Visual C++ 2010 Redistributable Package installed, and you probably do (it is automatically installed along with VS 2010), follow the steps outlined here to assist with the DirectX 10 installation. Once you have the DirectX 10 SDK installed, download and install the Windows 8 SDK here, which contains the DirectX 11 SDK. Yes, this is a pain, but unless you know you have the DirectX 11 SDK, the Qt build will fail.

从 Python 安装适用于 Windows 的 Python(我听说过 2.6+,使用 3.3).org 或 Anaconda Python.

从 ActiveState 安装 Perl for Windows.

Install Perl for Windows from ActiveState.

<小时>

第 2 步:Gitting(和构建)Qt5(是的,这意味着 Git)


Step 2: Gitting (and building) Qt5 (yes, that means Git)

  1. 遵循 qt-project 网站上的Windows 安装指南.

总结

总结以上链接和以下注释中的详细信息(如果您有任何错误,请参阅以下注释;它们可能会得到解答):

To summarize the details from the above link and from the following notes (PLEASE SEE FOLLOWING NOTES if you have any errors; they might be answered):

  • 卸载 Avast(如果已安装)以避免构建错误.是的,字面意思是卸载.将其 100% 从您的系统中删除.停用它不起作用.请参阅下面的详细说明.

  • Uninstall Avast (if you have this installed) to avoid build errors. Yes, that literally means uninstall it. Remove it 100% from your system. Deactivating it will not work. See detailed notes below.

第一步注意:不要在下面的第一次 git pull 中使用 SmartGit(除非你真的知道你在做什么),因为SmartGit 的默认设置将拉一切,而这不是您想要的.

Note for the first steps: DO NOT use SmartGit for the first git pull, below (unless you really know what you're doing), as SmartGit's defaults will pull everything, and that's not what you want.

Git for Windows 必须安装.

决定要将 Qt 安装和 cd 放在将包含任何命令提示符窗口中的新安装的目录中的位置.(因为这个过程非常脆弱且容易出错,我个人直接把它放在 C: 中,但这可能没有必要).

Decide where you want to put the Qt installation, and cd to the directory that will contain the new installation from any Command Prompt window. (Because the process is so fragile and error-prone, I personally put it directly in C:, but this is likely not necessary).

从上面的目录,执行:

git clone git://gitorious.org/qt/qt5.git qt5

这很快.完成后,您应该在 'stable' 分支上,但是您始终可以在 cd 进入新创建的 qt5 后运行 git checkout stable> 目录,只是为了确定.使用 git checkout 5.4.1 已确认适用于 VS2013 64 位.

This is fast. Once complete, you should be on the 'stable' branch, but you can always run git checkout stable after cding into the newly-created qt5 directory, just to be sure. Using git checkout 5.4.1 is confirmed to work with VS2013 64-bit.

关闭当前的命令提示符窗口(如果它不是 Visual Studio 命令提示符窗口),然后再继续下一步.这是为了确保您在接下来的步骤中使用 Visual Studio 命令提示窗口.

Close out of your current command prompt window (if it's not a Visual Studio command prompt window) before proceeding to the next step. This is to make sure you're using the Visual Studio command prompt window in the next steps.

接下来运行 32 位 (x86) 或 64 位 VS Tools 命令提示符(取决于您将 Qt5 构建为 32 位还是 64 位).要访问它,您必须通过开始菜单找到它 - 转到 Program Files -> [Microsoft] Visual Studio 2012/2013 -> Visual Studio Tools,你会在里面看到一个有趣的名字;名称应包含短语Native Tools;32 位版本的名称中将包含 x86,而 64 位版本的名称中将包含 x64.

Next run the 32-bit (x86) or 64-bit VS Tools command prompt (depending on whether you're building Qt5 as 32- or 64-bit). To access this, you must find it through the Start menu - go to Program Files -> [Microsoft] Visual Studio 2012/2013 -> Visual Studio Tools, and you'll see it in there with a funny name; the name should include the phrase Native Tools; the 32-bit version will have x86 in the name and the 64-bit version will have x64 in the name.

cd 进入上一步新建的 qt5 目录.

cd into the newly-created qt5 directory from the step above.

必须从 Visual Studio 命令提示符下载其余的 Qt 子模块:

From within the Visual Studio command prompt, the remainder of the Qt submodules must be downloaded:

perl ./init-repository --no-webkit

执行此步骤需要一些时间,因为它必须下载大量内容,但在良好的连接下还不算太糟糕.

It takes kind of a while to execute this step, because it has to download a lot, but it's not too terrible on a decent connection.

然后下载 init-repository 未下载的任何剩余可选子模块 - SmartGit 仅在此阶段开始运行良好(请参阅下面的评论).

Then download any remaining OPTIONAL submodules that init-repository does not download - SmartGit works well only starting at this stage (see comments below).

Qt 下载完成后,以下命令准备构建环境(也应使用 [32|64] VS Native Tools 命令提示符执行):

Once the download of Qt is complete, the following command prepares the build environment (it should also be executed using the [32|64] VS Native Tools Command Prompt):

configure -developer-build -opensource -confirm-license -mp -nomake examples -nomake tests -debug-and-release -c++11 -no-warnings-are-errors -platform win32-msvc2012.

此命令行的注意事项:c++11 选项对于 VS2012 编译器可能不是必需的,但适用于 VS2013;-no-warnings-are-errors 是必要的,以防您在 64 位自动构建 ANGLE 时遇到错误;-platform 自动设置为 win32-msvc2012,因此默认使用 Qt 的 32 位构建,并且命令中可能不需要提供 -platform行(即使您安装了以前版本的 VS).对于 VS2013,使用 -platform win32-msvc2013.

Notes on this command line: the c++11 option might not be necessary with the VS2012 compiler, but works with VS2013; the -no-warnings-are-errors is necessary in case you get errors on a 64-bit automatic build of ANGLE; -platform is automatically set to win32-msvc2012, so by default the 32-bit build of Qt is used, and -platform probably does not need to be supplied at the command line (EVEN if you have previous versions of VS installed). For VS2013, use -platform win32-msvc2013.

执行这一步需要几分钟,但还不错.

It takes a few minutes to execute this step, but it's not so bad.

最后,在系统上实际构建 Qt 的命令(也在 VS Native Tools 命令提示符中运行)很简单:

Finally, the command to actually build Qt on the system (also run within the VS Native Tools Command Prompt) is simply:

nmake

预计要等待数小时才能完成构建.如果您使用 -prefix 指定了输出文件夹(请参阅下面的注释),则使用 nmake install,否则就是这样.

Expect to wait hours for the build to complete. If you specified an output folder with -prefix (see notes below), then use nmake install, otherwise that's it.

<小时>

注意:

一般注意事项

如果您对上面链接的文档感到困惑,只是一个仅供参考,将使用 ANGLE 库(默认情况下)而不是 OpenGL,这就是您必须安装 DirectX 11 的原因.

In case you're confused from the above-linked documentation, just an FYI that the ANGLE library will be used (by default) instead of OpenGL, and that's why you had to install DirectX 11, above.

确保您使用 VS Native Tools 命令提示符运行上述链接中的所有命令(即 perl .init-repository --no-webkitconfigurenmake).您将使用 [32|64] 位命令提示符(x86x64),具体取决于您是将 Qt 构建为 32 位还是 64 位.如果在命令提示符打开的情况下安装 perl(确保它在 PATH 中),则需要重新启动命令提示符以使 perl 被识别为命令.

Make sure that you use the VS Native Tools Command Prompt to run all commands from the above link (that is, perl .init-repository --no-webkit, configure, and nmake). You will use the [32|64] bit command prompt (x86 or x64), depending on whether you are building Qt as 32-bit or 64-bit. If you install perl with the Command Prompt open (make sure it is in the PATH), you will need to restart the Command Prompt for perl to be recognized as a command.

运行init-repository"时(来自上面链接中的步骤),文档中并不清楚,但您必须通过 perl 执行它;即 perl ./init-repository --no-webkit.但是,configurenmake 命令是直接调用的.

When running "init-repository" (from the steps in the above link), it's not clear from the documentation, but you must execute this via perl; i.e. perl ./init-repository --no-webkit. The configure and nmake commands, however, are called directly.

传递给 configure 的一个非常有用的选项是 -mp,它会导致 Qt 在多个内核上并行构建,从而显着加快(长)构建时间.

One very useful option to pass to configure is -mp, which causes Qt to build on multiple cores in parallel, significantly speeding up the (long) build time.

要指定输出文件夹,请将 -prefix [outfolder] 添加到 configure 命令.例如,使用 -prefix %CD%outputx64vc12 将是适合 64 位 Visual Studio 2013 (12.0) 构建的输出(子)文件夹.

To specify an output folder add the -prefix [outfolder] to the configure command. For example, use -prefix %CD%outputx64vc12 would be a suitable output (sub)folder for a 64-bit Visual Studio 2013 (12.0) build.

Unicode 支持 (ICU)

如果您想要 Unicode 支持(通过 ICU),请特别注意注明的说明在上面的链接中.总之,ICU 必须在 VS 2012 中从头开始构建,因为 Windows 的唯一预构建 ICU 二进制文件是针对 VS 2010 的.在 VS 2012 中构建是无痛的 - 只需在 <icuroot>icu 中找到 ICU 解决方案 (.sln)sourceallinone,并在 Debug 和 Release 模式下构建(在 32 位或 64 位模式下,取决于您构建 Qt 的模式 - 不要构建其他位,因为 ICU 将覆盖输出文件夹与二进制文件).(Qt 构建过程将正确定位 ICU 的调试版本与发布版本.)它应该没有错误地构建.然后,将 <icuroot>lib 的路径添加为名为LIB"的(可能)新 Windows 环境变量中的字符串条目(您可以为此使用 Rapid EE;即使存在只有 1 个条目),并将路径添加到 <icuroot>include 作为字符串条目(可能)称为INCLUDE"的新 Windows 环境变量.(注意:将这些路径添加到 PATH 变量将不起作用.)在构建 Qt 之后,您可以删除所有刚刚添加的这些条目.此外,将 ICU dll (in) 的运行时路径添加到环境的 PATH 变量中,否则 Qt 构建过程(特别是当 uic.exe 运行时)将给出一个 欺骗性和误导性错误.最后,在 configure 命令行(如下),一定要添加 -icu 作为额外的命令行参数.

If you want Unicode support (via ICU), pay special attention to the instructions noted within the link above. In summary, ICU must be built from scratch in VS 2012, as the only prebuilt ICU binaries for Windows are for VS 2010. Building in VS 2012 is painless - simply locate the ICU solution (.sln) in <icuroot>icusourceallinone, and build in both Debug and Release mode (either in 32-bit or 64-bit mode, depending on which mode you're building Qt in - DO NOT build in the other bitness, because ICU will overwrite the output folder with the binaries). (The Qt build process will properly locate the debug vs. release build of ICU.) It should build without errors. Then, add the path to <icuroot>lib as a string entry in a (probably) NEW Windows environment variable called "LIB" (you can use Rapid EE for this; make LIB an "expandable string" in RapidEE even though there's only 1 entry), and also add the path to <icuroot>include as a string entry in a (probably) NEW Windows environment variable called "INCLUDE". (Note: Adding these paths to the PATH variable will not work.) After Qt is built, you can remove all of these entries you've just added. Also, do add the runtime path to the ICU dll's (<icuroot>in) to the environment's PATH variable, or the Qt build process (specifically, when uic.exe runs) will give a deceptive and misleading error. Finally, on the configure command line (below), be sure to add -icu as an additional command-line parameter.

ICU 故障:

目前,当启用 ICU 时,使用 VS2012 编译器构建 Qt5 似乎存在错误.具体来说,qtbasesrccorelibcodecsqtextcodec.cpp 第 688 行(Qt5 v5.02)未能返回编解码器名称US-ASCII"(编解码器为 NULL)的编解码器,导致"lrelease.exe"在稍后尝试取消引用编解码器时崩溃(我已经忘记了该文件/行号,但它显然是对 NULL codec 变量的取消引用).不幸的是,这意味着,据我所知,WebKit 无法使用(至少)32 位版本的 Qt5 和 VS2012 编译器构建,因为 WebKit 需要 ICU.

Currently, there seems to be a bug building Qt5 with the VS2012 compiler WHEN ICU IS ENABLED. Specifically, qtbasesrccorelibcodecsqtextcodec.cpp Line 688 (Qt5 v5.02) fails to return a codec for codec name "US-ASCII" (the codec is NULL), causing "lrelease.exe" to crash when trying to dereference the codec later (I have lost track of that file/line number, but it is an obvious dereference of the NULL codec variable). Unfortunately, this means that to my knowledge, WebKit cannot be built with (at least the) 32-bit build of Qt5 with the VS2012 compiler, because WebKit requires ICU.

如果有人能够在启用 ICU 的情况下使用 VS2012 编译器构建 Qt5,请更新此 Wiki.

ICU 说明:

如果您的路径中有 ICU,Qt 将自动构建它.换句话说,标志-icu"是隐含的.但是,这会导致如上所述的lrelease.exe"错误.所以解决这个问题的方法是在配置命令中添加标志 -no-icu

If you have ICU in your path, Qt will automatically built it. In other words, the flag "-icu" is there implicitly. However, this causes an error with "lrelease.exe" as mentioned above. So the way around this would be to add the flag, -no-icu to the configure command

其他子模块

如果您想要除默认子模块之外的子模块,您可以在完成init-repository 命令.SmartGit 可能是最简单的,因为您不需要将路径复制到命令行,而是可以直接使用用户界面.

If you want submodules in addition to the default submodules, you can use SmartGit (or command line) after you complete the init-repository command. SmartGit is perhaps easiest, because you do not need to copy the path to the command line, but can use the user interface directly.

警告:不要下载可选的 qlalr 子模块,因为它不会与整个 Qt 构建结合构建,也不是Qt 用户需要,但仅用于 Qt 内部开发.

WARNING: DO NOT DOWNLOAD THE OPTIONAL qlalr SUBMODULE, as it will not build in combination with the overall Qt build, and is not necessary for users of Qt, but is only used for internal Qt development.

警告: 必须使用 shell 命令行,后跟 perl .init-repository --no-webkit(不是 SmartGit);这些步骤只会正确下载默认的 Qt 子模块.您必须不要使用 SmartGit 从 git://gitorious.org/qt/qt5.git 克隆和下载 Git 文件,因为 SmartGit 当前无法正确处理子模块.相反,打开标准的 Windows shell 命令提示符(使用任何命令提示符应用程序,不一定是 VS Tools 命令提示符),并且(假设 Git 已正确安装在系统上;SmartGit 安装可能会也可能不会自动执行此操作;如果它没有,去Git for Windows 直接安装)输入git clone git://gitorious.org/qt/qt5.git 直接从命令行;也许遵循 git checkout stable (我不确定这个分支是否默认被签出);然后使用命令行 perl .init-repository --no-webkit 拉下 DEFAULT 存储库(WebKit 除外,它需要 ICU 和 ICU 似乎无法在 32 位 Qt5 中构建VS2012;见评论).

WARNING: A shell command line, followed by perl .init-repository --no-webkit, must be used (NOT SmartGit); these steps will properly only download the default Qt submodules. You must not use SmartGit to clone and download the Git files from git://gitorious.org/qt/qt5.git because SmartGit does not currently handle the submodules properly. Instead, open a standard Windows shell command prompt (using any command-prompt application, not necessarily the VS Tools command prompt), and (assuming Git is properly installed on the system; a SmartGit installation might or might not do this automatically; if it does not, go to Git for Windows and install directly) type git clone git://gitorious.org/qt/qt5.git directly from the command line; perhaps follow that with git checkout stable (I'm not sure if this branch is checked out by default); then follow that with the command line perl .init-repository --no-webkit to pull down the DEFAULT repositories (except WebKit, which requires ICU and ICU seemingly cannot be built in 32-bit Qt5 with VS2012; see comments).

因此,下载所有必需的 Qt 源文件的步骤是:1、使用Windows命令行执行初始git clone git://gitorious.org/qt/qt5.git;2. 在 VS Tools 2012 命令提示符中执行 perl .init-repository --no-webkit;然后可选3. 使用 SmartGit(来自上面的链接)(或等效的)打开一个现有的项目"(选择 Qt5 根文件夹)并从 SmartGit 中拉取以下载任何非默认存储库(但不要下载 qlalr).而已;您的系统上拥有所有必要和可选的 Qt 文件(包括子模块).

The steps for downloading all necessary Qt source files therefore are: 1. Use a Windows command line to execute the initial git clone git://gitorious.org/qt/qt5.git; 2. Execute perl .init-repository --no-webkit from within a VS Tools 2012 Command Prompt; and then optionally 3. Use SmartGit (from above link) (or equivalent) to "open an existing project" (choose the Qt5 root folder) and do a Pull from within SmartGit to download any non-default repositories (but do not download qlalr). That's it; you have all necessary and optional Qt files (including submodules) on your system.

如果有人发现无法构建和/或仅供内部使用的其他可选子模块(除了 qlalr),请更新此 Wiki 以指定它们.

If anybody discovers other optional submodules that fail to build and/or are for internal use only (besides qlalr), please update this Wiki to specify them.

一般来说,通过 perl .init-repository --no-webkit 获得的默认子模块就足够了.如果您知道或稍后发现其他(非默认)模块,您可以随时添加它们.

In general, the default submodules obtained via perl .init-repository --no-webkit are sufficient. If you know, or later find out, that you other (non-default) modules, you can always add them later.

一般问题

如果您在某些时候收到错误消息,指出无法识别命令python"(或任何类似的东西),只需检查包含 python.exe(或相应的 .exe) 是路径变量的一部分.如果不是,请添加它(为了方便起见,请使用上面提到的 RapidEE)并再次尝试您正在执行的操作.如果存在,请确保在将命令添加到路径后重新启动命令提示符.

If at some point you get the error saying that the command "python" (or anything similar) is not recognized, just check that the folder containing python.exe (or the appropriate .exe) is part of the path variable. If it is not, add it (use RapidEE as noted above for convenience) and try what you were doing again. If it is there, make sure you have restarted your command prompt AFTER the addition of the command to the path.

另外两个与路径相关的问题需要注意(引自与上述链接相关的文档):确保在 msysgit 提供的 perl 可执行文件之前的路径中找到 perl 可执行文件,因为后者已过时";和如果 sh.exe 在您的 PATH 中,您可能无法构建(例如,由于 git 或 msys 安装).这样的错误由 qt5-srcqtbasebinqmake.exe: command not found 等指示.在这种情况下,请确保 sh.exe 不在您的路径中.如果您的安装已经配置,则必须重新配置."

Two other path-related issues are important to note (quoted from the documentation associated with the link above): "Make sure the perl executable is found in the path before the perl executable provided by msysgit, since the latter is outdated"; and "You might not be able to build if sh.exe is in your PATH (for example due to a git or msys installation). Such an error is indicated by qt5-srcqtbasebinqmake.exe: command not found and alike. In this case, make sure that sh.exe is not in your path. You will have to re-configure if your installation is already configured."

在此过程中,您可能会在文件上使用 nmake 遇到错误.如果这样做,只需进入该目录并强制构建问题文件.然后再次在 Qt5 上开始 nmake 过程.

During the process, you may encounter an error using nmake on a file. If you do, just go into that directory and force build the problem file. Then begin the nmake process on Qt5 again.

具体问题

警告:您可能需要在 Qt nmake 过程中禁用防病毒软件和沙盒(为了安全起见,在整个过程中过程).在内部,Qt 会执行许多防病毒程序可能会干扰的可执行文件(有时是静默的).特别是,如果您有任何沙盒软件,请务必禁用沙盒.

WARNING: You may need to disable antivirus software AND SANDBOXING during the Qt nmake process (and, to be safe, throughout this entire process). Internally, Qt executes a number of executables that antivirus programs can interfere with (sometimes silently). In particular, if you have any sandboxing software, be SURE to disable sandboxing.

警告: AVAST! 沙盒用户:Avast 沙盒有一个错误,即使您禁用 Avast 的自动沙盒,沙盒也不会关闭,它会静默在 Qt 的构建过程中,将 Qt 的 rcc 程序自动创建的所有资源文件沙箱化.对于任何安装了 Avast 自动沙盒功能的用户,Qt 构建总是失败,即使自动沙盒关闭.解决此问题的唯一方法是完全卸载 AVAST!在构建 Qt 之前从您的系统.您可以重新安装 Avast!在 Qt 构建完成后.

WARNING: AVAST! Sandbox users: Avast Sandbox has a bug in which even when you disable Avast's auto-sandbox, the sandbox will NOT turn off and it will silently sandbox all resource files automatically created by Qt's rcc program during Qt's build process. The Qt build ALWAYS fails for any user who has installed the Avast autosandbox feature, EVEN WITH AUTO-SANDBOXING TURNED OFF. THE ONLY WAY TO OVERCOME THIS ISSUE IS TO COMPLETELY UNINSTALL AVAST! FROM YOUR SYSTEM before building Qt. You can reinstall Avast! after the Qt build is complete.

Qt5 的编译可能需要很长时间(数小时,即使使用 -mp 多线程选项).耐心.

The compilation of Qt5 can take a long time (hours, even with the -mp multithreading option). Patience.

  1. 下载并安装 Visual Studio Qt5 插件.它位于页面底部附近的其他下载"部分,不适用于 Visual Studio Express.

  1. Download and install the Visual Studio Qt5 addin. It is in the "Other Downloads" section near the bottom of the page, and will not work with Visual Studio Express.

打开 Visual Studio 2012,然后转到 Qt 选项(位于顶部菜单栏的Qt5"下).

Open Visual Studio 2012, and go to Qt Options (It's under "Qt5" on the top menu bar).

在 Qt 版本选项卡中,检查 Qt5 是否已经存在.如果不是,点击添加,选择版本名称(可能是5.xx之类的名称),然后导航到包含qmake.exe的文件夹(通常是C:Qtqt5qtbase).

In the Qt Versions tab, check to see if Qt5 is already there. If it is not, click add, choose a version name (probably a name such as 5.x.x), and navigate to the folder containing qmake.exe (usually C:Qtqt5qtbase).

退出 Qt 选项对话框.

Exit the Qt Options dialog.

创建一个新的 Visual Studio 项目.当您看到 New Project 对话框时,您应该会看到 Qt5 Projects 模板选项.

Create a new Visual Studio Project. When you see the New Project dialog, you should see the Qt5 Projects Template option.

拥有新的 Qt 项目后,右键单击它并选择转换为 QMake 生成的项目".构建项目,然后再次右键单击它并选择将项目转换为 Qt 插件项目".再次构建,然后运行.您现在应该有一个可用的 Qt 项目.

Once you have your new Qt Project, right click on it and select "Convert to QMake generated project". Build the project, then right click on it again and select "Convert project to Qt Add-in project". Build again, then run. You should now have a working Qt Project.

<小时>

将 Qt5 添加到现有的 Visual Studio 2012 VC++ 项目

本节可能适合您,也可能不适合.如果您遇到问题或有其他/更好的解决方案,请发表评论或编辑相应的步骤.

  1. 在 VS 中右键单击您的项目,然后选择卸载项目".再次右键单击该项目,然后选择编辑[项目名称].vcxproj".这将打开项目文件,以便您可以向其中添加 Qt5.

  1. Right-click on your project in VS, and choose "unload project". Right click on the project again, and select "edit [project name].vcxproj". This opens the project file so you can add Qt5 to it.

转到 Global PropertyGroup,将 添加或更改为 Qt4VSv1.0.

Go down to the Global PropertyGroup, and add or change the <Keyword> to Qt4VSv1.0.

重新加载项目,然后右键单击并选择将项目转换为 Qt 插件项目"

Reload the project, then right-click and select "Convert project to Qt Add-in project"

等待转换完成(不会超过几秒钟),然后选择Qt5>Project Settings.转到 Modules 选项卡,并检查您希望项目依赖的模块(基本模块是 CoreWidgetsGUI).

Wait for the conversion to finish (it does not take more than a couple seconds), then choose Qt5>Project Settings. Go to the Modules tab, and check the modules you would like your project to rely on (the basic ones are Core, Widgets, and GUI).

按照此处的步骤,添加目录$(QTDIR)include.

Following the steps here, add the directory $(QTDIR)include.

注意:

如果您在任何时候包含 windows.h,则需要 #define NOMINMAX before 这样做以防止与 qdatetime.h.

If at any time you are including windows.h, you need to #define NOMINMAX before doing so to prevent conflict with qdatetime.h.

完成上述步骤后,您可以通过选择Qt5>Create basic .pro file使您的项目可供 Qt Creator 使用.

Once the above steps are done, you can make your project usable by Qt Creator by selecting Qt5>Create basic .pro file.

<小时>

结束说明:如果您有与本指南中包含的信息相关的问题,请将其作为新问题发布(此处不是答案),以及答案或答案链接可能会被添加.


ENDING NOTES: If you have a question related to the information contained in this guide, please post it as a new question (not an answer here), and the answer or a link to the answer may get added.

相关文章