C++ 使用 Visual Studio 2012 / Visual Studio 2013 构建 Qt5,并与 IDE 集成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15826893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Building Qt5 with Visual Studio 2012 / Visual Studio 2013, and integrating with the IDE
提问by MirroredFate
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?
如何让 Qt5 下载并与 Visual Studio 2012 集成?您会遇到哪些问题,您如何解决这些问题?
UPDATE re. Visual Studio 2013
更新重新。视觉工作室 2013
Successes are reported with Visual Studio 2013 as well, and the notes are being maintained for VS 2013.
Visual Studio 2013 也报告了成功,并且正在为 VS 2013 维护注释。
Also note that the focus of the questionis strongly on just buildingQt with Visual Studio. There are also notes about integrating with the Visual Studio IDE
另请注意,问题的重点是仅使用 Visual Studio构建Qt。还有关于与 Visual Studio IDE 集成的注意事项
回答by MirroredFate
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.
此方法经测试适用于 Visual Studio 2013。此处提供使用 Visual Studio 2012 和 2013 的预构建二进制文件,包括 OpenGL 版本。
Step 1: The Setup
第 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).
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 hereto 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 11SDK. Yes, this is a pain, but unless you know you have the DirectX 11 SDK, the Qt build will fail.
Install Python for Windows (I've heard 2.6+, working with 3.3) from Python.orgor Anaconda Python.
Install Perl for Windows from ActiveState.
在此处下载并安装 RapidEE 。RapidEE 是一个 windows 环境变量编辑器。它对这个过程的其余部分非常有用(一般来说)。
安装 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 11SDK。 是的,这很痛苦,但除非您知道自己拥有 DirectX 11 SDK,否则 Qt 构建将失败。
从Python.org或Anaconda Python安装 Python for Windows(我听说过 2.6+,使用 3.3)。
从ActiveState安装 Perl for Windows 。
Step 2: Gitting(and building) Qt5(yes, that means Git)
第 2 步:Gitting(和构建)Qt5(是的,这意味着 Git)
Follow the installation guide for Windowsat the qt-project website.
Summary
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):
Uninstall Avast (if you have this installed) to avoid build errors. Yes, that literally means uninstallit. Remove it 100% from your system. Deactivatingit will not work. See detailed notes below.
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 Windowsmust be installed.
Decide where you want to put the
Qt
installation, andcd
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 inC:
, but this is likely not necessary).From the above directory, execute:
git clone git://gitorious.org/qt/qt5.git qt5
This is fast. Once complete, you should be on the 'stable' branch, but you can always run
git checkout stable
aftercd
ing into the newly-createdqt5
directory, just to be sure. Usinggit checkout 5.4.1
is confirmed to work with VS2013 64-bit.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.
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 phraseNative Tools
; the 32-bit version will havex86
in the name and the 64-bit version will havex64
in the name.cd
into the newly-createdqt5
directory from the step above.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.
Then download any remaining OPTIONAL submodules that
init-repository
does not download - SmartGit works well only starting at this stage (see comments below).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
.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 towin32-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.
Finally, the command to actually build Qt on the system (also run within the VS Native Tools Command Prompt) is simply:
nmake
Expect to wait hours for the build to complete.If you specified an output folder with
-prefix
(see notes below), then usenmake install
, otherwise that's it.
按照qt-project 网站上的Windows 安装指南进行操作。
概括
总结以上链接和以下注释中的详细信息(如果您有任何错误,请参阅以下注释;它们可能会得到解答):
卸载 Avast(如果已安装)以避免构建错误。是的,字面意思是卸载它。从您的系统中 100% 删除它。 停用它是行不通的。请参阅下面的详细说明。
第一步注意:不要在
git
下面的第一次拉取中使用 SmartGit (除非您真的知道自己在做什么),因为 SmartGit 的默认设置会拉取所有内容,而这不是您想要的。必须安装Windows 版 Git。
从任何命令提示符窗口确定要放置
Qt
安装的位置,以及cd
包含新安装的目录。(因为这个过程非常脆弱且容易出错,我个人直接把它放在 中C:
,但这可能没有必要)。从上面的目录,执行:
git clone git://gitorious.org/qt/qt5.git qt5
这很快。完成后,您应该在“稳定”分支上,但您始终可以
git checkout stable
在cd
进入新创建的qt5
目录后运行,只是为了确定。使用git checkout 5.4.1
已确认适用于 VS2013 64 位。在继续下一步之前,关闭当前的命令提示符窗口(如果它不是 Visual Studio 命令提示符窗口)。这是为了确保您在接下来的步骤中使用 Visual Studio 命令提示窗口。
接下来运行 32 位 (x86) 或 64 位 VS Tools 命令提示符(取决于您将 Qt5 构建为 32 位还是 64 位)。要访问它,您必须通过“开始”菜单找到它 - 转到
Program Files
->[Microsoft] Visual Studio 2012/2013
->Visual Studio Tools
,您会在那里看到一个有趣的名字;名称应包括短语Native Tools
;32 位版本将包含x86
在名称中,而 64 位版本将包含x64
在名称中。cd
qt5
从上面的步骤进入新创建的目录。从 Visual Studio 命令提示符中,必须下载其余的 Qt 子模块:
perl ./init-repository --no-webkit
执行此步骤需要一些时间,因为它必须下载大量内容,但在良好的连接上并不算太糟糕。
然后下载所有
init-repository
未下载的剩余可选子模块- SmartGit 仅在此阶段开始运行良好(请参阅下面的评论)。Qt 下载完成后,以下命令准备构建环境(也应使用 [32|64] VS Native Tools 命令提示符执行):
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
.执行这一步需要几分钟,但还不错。
最后,在系统上实际构建 Qt 的命令(也在 VS Native Tools 命令提示符中运行)很简单:
nmake
预计等待数小时才能完成构建。如果您指定了一个输出文件夹
-prefix
(请参阅下面的注释),则使用nmake install
,否则就是这样。
NOTES:
笔记:
General Notes
一般注意事项
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.
如果您对上面链接的文档感到困惑,只是一个仅供参考,将使用 ANGLE 库(默认情况下)而不是 OpenGL,这就是您必须安装 DirectX 11 的原因,上面。
Make sure that you use the VS Native Tools Command Promptto 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.
请确保您使用VS自带工具命令提示符运行从上面的链接的所有命令(即perl .\init-repository --no-webkit
,configure
和nmake
)。您将使用 [32|64] 位命令提示符(x86
或x64
),具体取决于您将 Qt 构建为 32 位还是 64 位。如果在命令提示符打开的情况下安装 perl(确保它在 中PATH
),则需要重新启动命令提示符以使 perl 被识别为命令。
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.
运行“init-repository”时(来自上面链接中的步骤),文档中不清楚,但您必须通过perl
; 即perl ./init-repository --no-webkit
。在configure
和nmake
命令,但是,直接调用。
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.
传递给的一个非常有用的选项configure
是-mp
,这会导致 Qt 在多个内核上并行构建,从而显着加快(长)构建时间。
To specify an output folder add the -prefix [outfolder]
to the configure
command. For example, use -prefix %CD%\output\x64\vc12
would be a suitable output (sub)folder for a 64-bit Visual Studio 2013 (12.0) build.
要指定输出文件夹,请添加-prefix [outfolder]
到configure
命令中。例如,use-prefix %CD%\output\x64\vc12
将是适用于 64 位 Visual Studio 2013 (12.0) 版本的输出(子)文件夹。
Unicode Support (ICU)
Unicode 支持 (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>\icu\source\allinone, 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>\bin) 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.
如果您想要 Unicode 支持(通过ICU),请特别注意上面链接中注明的说明。总之,ICU 必须在 VS 2012 中从头开始构建,因为 Windows 的唯一预构建 ICU 二进制文件适用于 VS 2010。在 VS 2012 中构建是无痛的 - 只需在 <icuroot>\icu\source 中找到 ICU 解决方案 (.sln) \allinone,并在 Debug 和 Release 模式下构建(在 32 位或 64 位模式下,取决于您构建 Qt 的模式 - 不要构建其他位,因为 ICU 将覆盖输出文件夹二进制文件)。(Qt 构建过程将正确定位 ICU 的调试版本与发布版本。)它应该没有错误地构建。然后,将 <icuroot>\lib 的路径作为字符串条目添加到名为“LIB”的(可能)新 Windows 环境变量中(您可以为此使用 Rapid EE;使 LIB 成为“可扩展字符串” 在 RapidEE 中,即使只有 1 个条目),并将 <icuroot>\include 的路径作为字符串条目添加到(可能)名为“INCLUDE”的新 Windows 环境变量中。(注意:将这些路径添加到 PATH 变量将不起作用。)在构建 Qt 之后,您可以删除所有刚刚添加的这些条目。另外,做将 ICU dll (<icuroot>\bin) 的运行时路径添加到环境的 PATH 变量中,否则 Qt 构建过程(特别是在uic.exe
运行时)将给出具有欺骗性和误导性的错误。最后,在configure
命令行(如下),一定要添加-icu
一个额外的命令行参数。
ICU Failure:
ICU 故障:
Currently, there seems to be a bug building Qt5 with the VS2012 compiler WHEN ICU IS ENABLED. Specifically, qtbase\src\corelib\codecs\qtextcodec.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 似乎存在错误。具体来说,qtbase\src\corelib\codecs\qtextcodec.cpp
第 688 行 (Qt5 v5.02) 未能返回编解码器名称“US-ASCII”的编解码器(编解码器为 NULL),导致“lrelease.exe”在稍后尝试取消引用编解码器时崩溃(我已经迷失了方向)该文件/行号,但它显然是对 NULLcodec
变量的取消引用)。不幸的是,这意味着,据我所知,WebKit 不能用(至少)32 位版本的 Qt5 和 VS2012 编译器来构建,因为 WebKit 需要 ICU。
If anyone is able to build Qt5 with the VS2012 compiler with ICU enabled, please update this Wiki saying so.
如果有人能够在启用 ICU 的情况下使用 VS2012 编译器构建 Qt5,请更新此 Wiki 说明。
ICU Clarification:
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
如果您的路径中有 ICU,Qt 将自动构建它。换句话说,标志“ -icu
”是隐含的。但是,这会导致如上所述的“lrelease.exe”错误。所以解决这个问题的方法是在配置命令中添加标志 -no-icu
Additional Submodules
附加子模块
If you want submodules in additionto the default submodules, you can use SmartGit (or command line) afteryou 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.
如果除了默认子模块之外还想要子模块,可以在完成init-repository
命令后使用 SmartGit(或命令行)。SmartGit 可能是最简单的,因为您不需要将路径复制到命令行,而是可以直接使用用户界面。
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.
警告:不要下载可选的子qlalr
模块,因为它不会与整个 Qt 构建结合构建,并且对于 Qt 用户来说不是必需的,但仅用于内部 Qt 开发。
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 notuse 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 Windowsand 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).
警告:perl .\init-repository --no-webkit
必须使用后跟, 的shell 命令行(不是 SmartGit);这些步骤只会正确下载默认的 Qt 子模块。你不能使用 SmartGit 来克隆和下载 Git 文件,git://gitorious.org/qt/qt5.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
拉下默认存储库(WebKit 除外,它需要 ICU 并且 ICU 似乎无法使用 VS2012 在 32 位 Qt5 中构建;请参阅评论)。
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.
因此,下载所有必需的 Qt 源文件的步骤是: 1. 使用 Windows 命令行执行初始git clone git://gitorious.org/qt/qt5.git
; 2.perl .\init-repository --no-webkit
从 VS Tools 2012 命令提示符中执行;然后可选 3. 使用 SmartGit(来自上面的链接)(或等效项)“打开现有项目”(选择 Qt5 根文件夹)并从 SmartGit 中执行拉取以下载任何非默认存储库(但不要下载qlalr
) . 就是这样; 您的系统上拥有所有必需和可选的 Qt 文件(包括子模块)。
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.
如果有人发现无法构建和/或仅供内部使用的其他可选子模块(除了qlalr
),请更新此 Wiki 以指定它们。
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.
一般来说,通过获取的默认子模块perl .\init-repository --no-webkit
就足够了。如果您知道或稍后发现其他(非默认)模块,您可以随时添加它们。
General Problems
一般问题
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.
如果在某个时候您收到错误消息,指出无法识别命令“python”(或任何类似的东西),只需检查包含python.exe
(或相应.exe
)的文件夹是否是路径变量的一部分。如果不是,请添加它(为了方便起见,请使用上面提到的 RapidEE)并再次尝试您正在执行的操作。如果存在,请确保在将命令添加到路径后重新启动了命令提示符。
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."
另外两个与路径相关的问题需要注意(引自与上述链接相关的文档):“确保在 msysgit 提供的 perl 可执行文件之前的路径中找到 perl 可执行文件,因为后者已过时”;和“如果 sh.exe 在您的 PATH 中,您可能无法构建(例如由于 git 或 msys 安装)。这样的错误由 qt5-srcqtbasebinqmake.exe: command not found 等指示。在这种情况下,请确保 sh.exe 不在您的路径中。如果您的安装已经配置,则必须重新配置。”
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.
在此过程中,您可能会遇到nmake
在文件上使用的错误。如果这样做,只需进入该目录并强制构建问题文件。然后nmake
再次在 Qt5 上开始该过程。
Specific Problems
具体问题
WARNING:You may need to disable antivirus software AND SANDBOXINGduring 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.
警告:您可能需要在 Qt过程中禁用防病毒软件和沙盒nmake
(为了安全起见,在整个过程中)。在内部,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.
警告:AVAST!沙盒用户:Avast Sandbox 有一个错误,即使您禁用 Avast 的自动沙盒,沙盒也不会关闭,它会rcc
在 Qt 的构建过程中静默地将 Qt程序自动创建的所有资源文件进行沙盒化。对于安装了 Avast 自动沙盒功能的任何用户,Qt 构建总是失败,即使自动沙盒关闭。解决此问题的唯一方法是完全卸载 AVAST!在构建 Qt 之前从您的系统。您可以重新安装 Avast!Qt构建完成后。
The compilation of Qt5 can take a long time (hours, even with the -mp multithreading option). Patience.
Qt5 的编译可能需要很长时间(数小时,即使使用 -mp 多线程选项)。耐心。
Step 3: Integrating Qt5 with Visual Studio 2012
第 3 步:将 Qt5 与 Visual Studio 2012 集成
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.
Open Visual Studio 2012, and go to
Qt Options
(It's under "Qt5" on the top menu bar).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
(usuallyC:\Qt\qt5\qtbase
).Exit the Qt Options dialog.
Create a new Visual Studio Project. When you see the New Project dialog, you should see the
Qt5 Projects
Template option.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.
下载并安装 Visual Studio Qt5 插件。它位于页面底部附近的“其他下载”部分,不适用于 Visual Studio Express。
打开 Visual Studio 2012,然后转到
Qt Options
(它位于顶部菜单栏的“Qt5”下)。在 Qt 版本选项卡中,检查 Qt5 是否已经存在。如果不是,请单击添加,选择版本名称(可能是 5.xx 之类的名称),然后导航到包含
qmake.exe
(通常为C:\Qt\qt5\qtbase
)的文件夹。退出 Qt 选项对话框。
创建一个新的 Visual Studio 项目。当您看到“新建项目”对话框时,您应该会看到“
Qt5 Projects
模板”选项。有了新的 Qt 项目后,右键单击它并选择“转换为 QMake 生成的项目”。构建项目,然后再次右键单击它并选择“将项目转换为 Qt 插件项目”。再次构建,然后运行。您现在应该有一个有效的 Qt 项目。
Add Qt5 to an existing Visual Studio 2012 VC++ project
将 Qt5 添加到现有的 Visual Studio 2012 VC++ 项目
This section may or may not work for you. If you run into problems or have additional/better solutions, please leave a comment or edit the appropriate step.
本节可能适合您,也可能不适合。如果您遇到问题或有其他/更好的解决方案,请发表评论或编辑适当的步骤。
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.
Go down to the Global PropertyGroup, and add or change the
<Keyword>
to Qt4VSv1.0.Reload the project, then right-click and select "Convert project to Qt Add-in project"
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 areCore
,Widgets
, andGUI
).Following the steps here, add the directory
$(QTDIR)\include
.NOTES:
If at any time you are including
windows.h
, you need to#define NOMINMAX
beforedoing so to prevent conflict withqdatetime.h
.Once the above steps are done, you can make your project usable by Qt Creator by selecting
Qt5>Create basic .pro file
.
在 VS 中右键单击您的项目,然后选择“卸载项目”。再次右键单击该项目,然后选择“编辑 [项目名称].vcxproj”。这将打开项目文件,以便您可以向其中添加 Qt5。
转到 Global PropertyGroup,并将其添加或更改
<Keyword>
为 Qt4VSv1.0。重新加载项目,然后右击并选择“Convert project to Qt Add-in project”
等待转换完成(不会超过几秒钟),然后选择
Qt5>Project Settings
。转到模块选项卡,并检查模块,你想你的项目依赖于(基本的有Core
,Widgets
和GUI
)。按照此处的步骤添加目录
$(QTDIR)\include
。笔记:
如果您在任何时候包含
windows.h
,则需要#define NOMINMAX
在这样做之前防止与qdatetime.h
.完成上述步骤后,您可以通过选择 使您的项目可供 Qt Creator 使用
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.
结束说明:如果您有与本指南中包含的信息相关的问题,请将其作为新问题发布(此处不是答案),并且可能会添加答案或答案链接。
回答by Ronald Souza
I successfully managed to integrate Qt 5.0.2 with Visual Studio 2012 on Windows 7 based on the excellent wiki above and on this qt-project linkas well. Since I made some of the steps on a slightly different way, I thought it would be valid to post it in here:
我成功地将 Qt 5.0.2 与 Windows 7 上的 Visual Studio 2012 基于上面的优秀维基和这个 qt-project 链接以及。由于我以稍微不同的方式制作了一些步骤,因此我认为将其发布在这里是有效的:
The sequence below should be executed in the exact given order:
下面的序列应该按照给定的确切顺序执行:
0 - Uninstall Avast (if you have this installed) to avoid build errors. Due to an Avast bug, deactivating it will not work;
0 - 卸载 Avast(如果已安装)以避免构建错误。由于 Avast 错误,停用它不起作用;
1 - Install Git (>= 1.6.x);
1 - 安装 Git (>= 1.6.x);
2 - Install Python (>=2.6.x). [python.org];
2 - 安装 Python (>=2.6.x)。[python.org];
3 - Install Perl (>=5.14). [activestate.com];
3 - 安装 Perl (>=5.14)。[activestate.com];
4 - Install Ruby. [rubyinstaller.org];
4 - 安装 Ruby。[rubyinstaller.org];
5 - Open the Windows 7 Command Prompt (don't use VS2012 Developer Command Prompt by now);
5 - 打开 Windows 7 命令提示符(现在不要使用 VS2012 开发人员命令提示符);
6 - Choose any directory you want for qt5, regarding that NO SPACES ARE ALLOWEDfor the chosen path. I decided to use the path "C:\qt5";
6 - 为 qt5 选择您想要的任何目录,关于所选路径不允许空格。我决定使用路径 "C:\qt5";
7 - Back to Windows 7 Command Prompt (in my case, prompting "C:\qt5>") type:
7 - 回到 Windows 7 命令提示符(在我的例子中,提示“C:\qt5>”)输入:
git clone git://gitorious.org/qt/qt5.git qt5
8 - Checkout the stable version:
8 - 检查稳定版本:
cd qt5
git checkout stable
9 - You'll probably receive a message confirming that this version is already stable. Close the Command Prompt;
9 - 您可能会收到一条消息,确认此版本已经稳定。关闭命令提示符;
10 - Open Visual Studio's Developers Console (All Programs > Visual Studio 2012 > Visual Studio Tools > Developer Command Prompt for VS2012)and change the current directory to the one you have chosen("C:\qt5" in my example);
10 - 打开 Visual Studio 的开发人员控制台(所有程序 > Visual Studio 2012 > Visual Studio Tools > Developer Command Prompt for VS2012)并将当前目录更改为您选择的目录(在我的示例中为“C:\qt5”);
11 - Download Qt submodules, ignoring webkit (common source of build errors...):
11 - 下载 Qt 子模块,忽略 webkit(构建错误的常见来源...):
perl .\init-repository --no-webkit
12 - Now enter this huge command to configure your build properly:
12 - 现在输入这个巨大的命令来正确配置你的构建:
configure -developer-build -opensource -nomake examples -nomake tests -nomake demos -debug-and-release -c++11 -mp -nomake webkit -confirm-license
13 - Next, ensure that the module qlalrwill NOTbe built. To do this, open Windows Explorer and navigate to your chosen Qt directory ("C:\qt5" in my example) and check if the folder qlalrexists. If so, delete it;
13 -接下来,确保模块qlalr将不建。为此,请打开 Windows 资源管理器并导航到您选择的 Qt 目录(在我的示例中为“ C:\qt5”)并检查文件夹qlalr 是否存在。如果是,删除它;
14 - Time to build... Possible build errors would come from secondary modules (such as webkit), which don't affect the main Qt functionality (webkit itself should not be a problem since we've previously set the configuration not to build it). We can then ignore them and also keep the build running on independent modules:
14 - 构建时间... 可能的构建错误来自次要模块(例如 webkit),它们不会影响主要的 Qt 功能(webkit 本身应该不是问题,因为我们之前已经将配置设置为不构建它)。然后我们可以忽略它们并保持构建在独立模块上运行:
nmake /I /K
15 - To conclude integration, follow the step 3 of the community wiki above("Step 3: Integrating Qt5 with Visual Studio 2012").
15 - 要完成集成,请按照上面社区维基的第 3 步(“第 3 步:将 Qt5 与 Visual Studio 2012 集成”)。
回答by Beachwalker
Just want to mention that there is a prebuilt version of Qt 5.2 for Visual Studio 2012 available at http://qt-project.org/downloads. So if you don't have a special interest in building Qt 5 from sources you can use the prebuild binaries, too.
只想提一下,在http://qt-project.org/downloads上有一个适用于 Visual Studio 2012 的 Qt 5.2 的预构建版本。因此,如果您对从源代码构建 Qt 5 没有特别兴趣,您也可以使用预构建二进制文件。
There are also several precompiled (x64) binaries for different compiler versions available at the Tver-Soft website.
Tver-Soft 网站上还有一些针对不同编译器版本的预编译 (x64) 二进制文件。
回答by Dmitry
I was finally able to compile QT 5.1 (git) with QWebKit on Windows 8 x64 using Visual Studio 2012 and figured I'd share my experience with those that had problems as well.
我终于能够使用 Visual Studio 2012 在 Windows 8 x64 上用 QWebKit 编译 QT 5.1 (git) 并认为我也会与那些有问题的人分享我的经验。
Did step 1 and 2 as stated in the above post. I tried to do step 3 but SmartGit pulled a bunch of extra projects that wouldn't compile with Qt5. I was able to solve most of the problems by cloning from a different fork (e.g. https://qt.gitorious.org/qt/qt3d/), but this became too tedious to do for every extra module, so I decided against compiling any of them.
执行上述帖子中所述的第 1 步和第 2 步。我尝试执行第 3 步,但 SmartGit 提取了一堆无法使用 Qt5 编译的额外项目。我能够通过从不同的分支(例如https://qt.gitorious.org/qt/qt3d/)进行克隆来解决大部分问题,但是对于每个额外的模块来说这变得太乏味了,所以我决定不编译任何一位。
The post at ICU support in a 32-bit build of Qt5 with the VS2012 compiler causes Qt5 build failure; Webkit is also therefore unbuildabletold me how to fix the ICU problem.
在柱中QT5与VS2012编译一个32位构建ICU支持导致QT5生成失败; Webkit 也因此 unbuildable告诉我如何解决 ICU 问题。
Download the source code at http://download.icu-project.org/files/icu4c/51.2/icu4c-51_2-src.zipand add the line
在http://download.icu-project.org/files/icu4c/51.2/icu4c-51_2-src.zip下载源代码并添加行
#define U_CHARSET_IS_UTF8 1
to the file %ICU%\source\common\unicode\platform.h , where %ICU% is the path to the ICU source code.
到文件 %ICU%\source\common\unicode\platform.h ,其中 %ICU% 是 ICU 源代码的路径。
Open %ICU%\source\allinone\allinone.sln file in Visual Studio 2012 and compile. Add %ICU%\bin to your path
在 Visual Studio 2012 中打开 %ICU%\source\allinone\allinone.sln 文件并编译。将 %ICU%\bin 添加到您的路径中
set PATH=%ICU%\bin64;%PATH%
Then I ran the following command in the QT root directory
然后我在QT根目录下运行以下命令
configure -platform win32-msvc2012 -opengl desktop -opensource -debug-and-release -I %ICU%\include -L %ICU%\icu\lib64 -mp -qt-freetype -icu
At this point I started to suspect that no one tried to do what I was doing, because nmake started to complain about unexpected lines in the makefiles (all of which had the extension DerivedSources, e.g. Makefile.JavaScriptCore.DerivedSources and Makefile.WebCore.DerivedSources))
在这一点上,我开始怀疑没有人试图做我正在做的事情,因为 nmake 开始抱怨 makefile 中的意外行(所有这些都具有扩展名 DerivedSources,例如 Makefile.JavaScriptCore.DerivedSources 和 Makefile.WebCore.DerivedSources ))
(set PATH=<stuff>;%PATH%) && ....
do the set PATH manually before running nmake and delete the characters up to and including && e.g.
在运行 nmake 之前手动设置 PATH 并删除直到包括 && 的字符,例如
(set PATH=<stuff>;%PATH%) && perl -ne "print " css\CSSPropertyNames.in ...
Becomes
成为
perl -ne "print " css\CSSPropertyNames.in ...
Finally, one of these files will try to call win_flex.exe (or win-flex.exe) instead of flex. I changed it to flex.exe and everything finally compiled (Had to change it twice, because I think the file got regenerated).
最后,这些文件之一将尝试调用 win_flex.exe(或 win-flex.exe)而不是 flex。我将其更改为 flex.exe 并最终编译所有内容(不得不更改两次,因为我认为该文件已重新生成)。
Brief experience with a program that uses QWebKit and linked against this build leads me to believe everything is fine.
使用 QWebKit 并链接到此构建的程序的简要经验使我相信一切都很好。
--Update--
- 更新 -
Just to be complete. According to What does (set PATH=...;%PATH:)=^)%) mean in a Windows shell script, and how can I overcome failure of this line in the context of a Qt5 nmake build?(which points to http://qt-project.org/forums/viewthread/20605) most of the Makefile problems should be solvable by using jsom instead of nmake (although I still wonder about win-flex.exe)
只是为了完整。根据(set PATH=...;%PATH:)=^)%) 在 Windows shell 脚本中是什么意思,以及如何在 Qt5 nmake 构建的上下文中克服此行的失败?(指向http://qt-project.org/forums/viewthread/20605)大多数 Makefile 问题应该可以通过使用 jsom 而不是 nmake 来解决(尽管我仍然想知道 win-flex.exe)
回答by hatranpro
compile Qt 5.5 with visual studio 2015:
使用 Visual Studio 2015 编译 Qt 5.5:
1- modefier configure.bat in qtbase directory so it can generate configure.exe (just the first 18 lines)
1- qtbase 目录下的 modifier configure.bat 以便它可以生成 configure.exe(仅前 18 行)
@echo off
set QTSRC=%~dp0
set QTDIR=%CD%
rem if not exist %QTSRC%.gitignore goto sconf
echo Please wait while bootstrapping configure ...
for %%C in (cl.exe icl.exe g++.exe perl.exe) do set %%C=%%~$PATH:C
rem if "%perl.exe%" == "" (
rem echo Perl not found in PATH. Aborting. >&2
rem exit /b 1
rem )
if not exist mkspecs (
md mkspecs
if errorlevel 1 goto exit
)
rem perl %QTSRC%bin\syncqt.pl -minimal -module QtCore -outdir "%QTDIR%" %QTSRC%
rem if errorlevel 1 goto exit
2- configure -opensource -confirm-license -mp -nomake examples -nomake tests -release -c++11 -no-warnings-are-errors -platform win32-msvc2015 -no-ltcg
2- configure -opensource -confirm-license -mp -nomake examples -nomake tests -release -c++11 -no-warnings-are-errors -platform win32-msvc2015 -no-ltcg
3- nmake
3- nmake