简体   繁体   English

如何为Visual Studio 2010构建Qt

[英]How to build Qt for Visual Studio 2010

I struggled finding a how-to which provides a stable solution for using Qt with Visual Studio 2010, so after collecting all the bits of information and some trial and error, I would like to write my solution into a guide. 我努力寻找一种方法,为使用Qt和Visual Studio 2010提供稳定的解决方案,因此在收集了所有信息和一些反复试验后,我想将我的解决方案写入指南。

The problem, or why is it not possible to use prebuilt binaries? 问题,或者为什么不能使用预构建的二进制文件?

It seems that using binaries built for Visual Studio 2008 might work in some special cases, but I found them not to work. 似乎使用为Visual Studio 2008构建的二进制文件可能在某些特殊情况下工作,但我发现它们无法工作。 In my case they compiled OK, but they produce runtime errors, like this: 在我的情况下,他们编译好,但他们产生运行时错误,如下所示:

problem2

or when started from Visual Studio 2010: 或者从Visual Studio 2010启动时:

问题

Update : I found a blog post analysing why does it work for some people, while it does not for others. 更新 :我发现一篇博客文章分析了为什么它适用于某些人,而不适用于其他人。 In one word, it depends on whether you have Visual Studio 2008 installed on the same machine, or not. 总之,这取决于您是否在同一台计算机上安装了Visual Studio 2008。 http://blog.paulnettleship.com/2010/11/11/troubleshooting-visual-studio-2010-and-qt-4-7-integration/ http://blog.paulnettleship.com/2010/11/11/troubleshooting-visual-studio-2010-and-qt-4-7-integration/

The most important thing (that I stupidly didn't realize) was the fact that you CANNOT use the Visual Studio 2008 compiled libraries and dll's (available on the Qt webpage) if you don't have Visual Studio 2008 installed. 最重要的是(我愚蠢地没有意识到),如果你没有安装Visual Studio 2008,你就不能使用Visual Studio 2008编译的库和dll(可在Qt网页上找到)。 The reason is because the Qt SDK you download is a debug build which is dependant on the VC9.0 DebugCRT, meaning it needs the Visual C++ 2008 Debug Runtime installed, which is NOT available as a redistributable installer. 原因是你下载的Qt SDK是一个调试版本,它依赖于VC9.0 DebugCRT,这意味着它需要安装Visual C ++ 2008 Debug Runtime,它不能作为可再发行的安装程序使用。 The only way to install the DebugCRT is to install the entirety of Visual Studio 2008. 安装DebugCRT的唯一方法是安装整个Visual Studio 2008。

First of all, it's very important to understand that for using Qt with Visual Studio 2010, it's not possible to use the pre-built binaries which were made for Visual Studio 2008 , but you have to compile it from source. 首先,了解在Visual Studio 2010中使用Qt非常重要, 不可能使用为Visual Studio 2008制作的预构建二进制文件 ,但必须从源代码编译它。

Downloading Qt 正在下载Qt

On https://www.qt.io/download/ https://www.qt.io/download/

Update 2017: the latest Qt 4.x branch (Qt 4.8.6) has 2 pre-built packages, which are now in the archive section: 2017年更新:最新的Qt 4.x分支(Qt 4.8.6)有2个预先构建的软件包,现在位于归档部分:

  1. http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2010-4.8.6.exe http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2010-4.8.6.exe
  2. http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2008-4.8.6.exe http://download.qt.io/archive/qt/4.8/4.8.6/qt-opensource-windows-x86-vs2008-4.8.6.exe

You should not download Qt by clicking "Qt libraries 4.8.6 for Windows (Visual Studio 2008, 218 MB)" , but by clicking on the "zip" link above it. 您不应该通过单击“Qt libraries 4.8.6 for Windows(Visual Studio 2008,218 MB)”下载Qt,而是单击其上方的“zip”链接。

链接选择

On that link, you get a big zip file like "qt-everywhere-opensource-src-4.8.6.zip" . 在该链接上,您将获得一个大型zip文件,如“qt-everywhere-opensource-src-4.8.6.zip” Unzip this into a folder and make its path something nice and small, for example "E:\\Qt" 将其解压缩到一个文件夹中,使其路径变得美观小巧,例如“E:\\ Qt”

Visual Studio Command Prompt Visual Studio命令提示符

Now that we have the sources, we need to build the binaries. 现在我们有了源代码,我们需要构建二进制文件。 To do it, open the Microsoft Visual Studio 2010\\Visual Studio Tools\\Visual Studio Command Prompt (2010) link from your start menu, or even pin it to the taskbar (a good idea). 为此,从开始菜单打开Microsoft Visual Studio 2010\\Visual Studio Tools\\Visual Studio Command Prompt (2010)链接,甚至将其固定到任务栏(一个好主意)。 This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools. 这是一个特殊的命令提示符,其中包含用于使用Visual Studio 2010工具进行构建的所有变量。

Once within the command prompt, navigate to your extracted Qt folder using old-school DOS way, which means you have to change drive letter by E: , enter directories by cd Qt and list dir contents by dir . 一旦命令提示符中,导航使用老派的DOS方式您提取的Qt文件夹,这意味着你必须通过改变驱动器盘符E:输入目录cd Qt和列出目录内容dir You can use the tab key for helping you with the directory names. 您可以使用Tab键来帮助您使用目录名称。 When you have arrived at the correct directory, a dir command should return something like this. 当你到达正确的目录时, dir命令应该返回这样的东西。

命令行

Building Qt 建立Qt

Now it's time for configure and build. 现在是配置和构建的时候了。 For configuring a minimalist Qt, I'm using the following flags with configure.exe . 为了配置极简主义的Qt,我在configure.exe使用以下标志。 Just copy and paste it into the command line. 只需将其复制并粘贴到命令行即可。 Look in the Qt reference manual for what flag to use or not to use. Qt参考手册中查看要使用或不使用的标志。

configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg

Once configure.exe has finished (it was 10 minutes for me), you'll need to start the build process. 一旦configure.exe完成(对我来说是10分钟),您将需要启动构建过程。 It will take about 20-30 minutes with the above flags. 使用上述标志需要大约20-30分钟。 To start it, just type: 要启动它,只需键入:

nmake

Setting environment variables 设置环境变量

Basically, we are done. 基本上,我们已经完成了。 All you need to do is to set your environment variables ( QTDIR and PATH ), which tell programs where to find Qt. 您需要做的就是设置环境变量( QTDIRPATH ),它告诉程序在哪里可以找到Qt。 If you are on Windows 7, you can use the following command to set QTDIR to your installation dir. 如果您使用的是Windows 7,则可以使用以下命令将QTDIR设置为安装目录。

setx QTDIR e:\Qt

For setting the PATH , I strongly recommend using Path Editor . 为了设置PATH ,我强烈建议使用路径编辑器 Within Path Editor 在路径编辑器中

add the directory of Qt\bin to your PATH

(it doesn't matter if it's in system path or user path) (如果它在系统路径或用户路径中无关紧要)

If you prefer to use Control Panel\\System\\Environment Variables , then you can set these there, too. 如果您更喜欢使用Control Panel\\System\\Environment Variables ,那么您也可以在那里设置它们。

Qt Visual Studio Add-in Qt Visual Studio加载项

Here you go, after a logoff-logon or a restart, all the Qt demo applications should start correctly (I recommend have a look at bin\\qtdemo.exe ). 注销登录或重新启动后,所有Qt演示应用程序应该正确启动(我建议看一下bin \\ qtdemo.exe )。 Now you can download and install the Visual Studio Add-in (qt-vs-addin-1.1.9.exe) from the Qt download page, it will work perfectly. 现在,您可以从Qt下载页面下载并安装Visual Studio加载项(qt-vs-addin-1.1.9.exe),它将完美运行。

加入

Appendix A: Official Instructions: 附录A:官方说明:

There is a page at the official wiki at the Qt website called Qt 4.8 Installing Qt for Windows , but I found it lacking important information. 在Qt网站的官方维基上有一个名为Qt 4.8安装Qt for Windows的页面 ,但我发现它缺少重要信息。

References 参考

Qt DevNet forums Qt DevNet论坛
Recommended flags for a minimalistic Qt build 简化Qt构建的推荐标志
Building Qt 4.5 with Visual C++ 2010 使用Visual C ++ 2010构建Qt 4.5
How to compile Qt as static 如何将Qt编译为静态
Qt 4.8: Configure options for Qt Qt 4.8:配置Qt的选项
Edit the PATH environment variable in 编辑PATH环境变量
Windows without pain - op111.net Windows没有痛苦 - op111.net

Qt V4.8.0包含Visual Studio 2010的预构建二进制文件,因此您不再需要这样做: http//qt.nokia.com/downloads/windows-cpp-vs2010

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM