如何建立Qt的为Visual Studio 2010 [英] How to build Qt for Visual Studio 2010

查看:408
本文介绍了如何建立Qt的为Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我挣扎着找到一个如何做这为使用Qt与Visual Studio 2010,所以收集的信息和一些试错的所有位后,我想写出我的解决方案在引导一个稳定的解决方案。

问题,或者它为什么不能使用prebuilt二进制文件?

看来,使用Visual Studio 2008中生成的二进制文件可能会在某些特殊情况下工作,但我发现他们无法正常工作。在我的情况下,他们编好了,但是他们生产的运行时错误,是这样的:

或Visual Studio 2010中启动时:

更新:我发现了一个博客文章分析它为什么对某些人工作,而它不为别人着想。一句话,它取决于你是否安装在同一台机器上的Visual Studio 2008,还是不行。
<一href=\"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/


  

最重要的事情(我愣神不知道)的事实,你不能使用Visual Studio 2008编译的库和动态链接库(可在Qt的网页),如果你没有Visual Studio 2008中安装有做。究其原因是因为Qt的SDK下载是调试版本是依赖于VC9.0 DebugCRT,这意味着它需要的Visual C ++安装2008调试运行时,这是不是可以作为一个可再分发安装。安装DebugCRT的唯一方法是安装Visual Studio 2008的全部内容。



解决方案

首先,是要明白,作为使用Qt与Visual Studio 2010中,它不是可以使用pre-建造是非常重要的它们被做成为Visual Studio 2008 ,但二进制文件你必须从源代码编译。

下载的Qt

http://qt.nokia.com/downloads ,点击LGPL。

更新:新的链接是在这里: http://qt-project.org/downloads

您不能下载的Qt点击的Qt库4.7.2为Windows(Visual Studio 2008中,218 MB)的,而是通过点击的拉链的链接上面。

在这个链接,你会得到像一个大的zip文件的qt-everywhere-opensource-src-4.7.2.zip的。这解压缩到一个文件夹,并使其路径一件好事,小,例如E:\\ Qt的

Visual Studio命令提示符

现在,我们有资源,我们需要建立的二进制文件。要做到这一点,打开微软的Visual Studio 2010 \\ Visual Studio工具\\ Visual Studio命令提示符(2010)链接从你的开始菜单,甚至可以将其固定到任务栏(一好主意)。这是对使用Visual Studio 2010工具构建中设置的所有变量一个特殊的命令提示符窗口。

在命令提示符下一次,导航用老派的DOS方式的提取Qt的文件夹,这意味着你必须用来改变驱动器盘符E:,通过进入目录 CD的Qt 并列出目录的内容由 DIR 。您可以使用Tab键可帮助您的目录名。当你已经在正确的目录来临, DIR 命令应返回这样的事情。

构建Qt

现在是时候进行配置和建设。对于配置简约Qt中,我使用的是 configure.exe 以下标志。只需复制并粘贴到命令行。看在 Qt的参考手册为使用什么标志或不使用。

  configure.exe -release -no-webkit的-no声子 - 无 - 声子后端-no脚本-no-scripttools -no-qt3support -no多媒体-NO- LTCG

configure.exe 已完成(对我来说是10分钟),你需要开始构建过程。这将需要约20-30分钟上述标志。要启动它,只需键入:

  NMAKE

设置环境变量

基本上,我们就完成了。所有你需要做的是设置环境变量( QTDIR PATH ),它告诉程序在哪里可以找到的Qt 。如果您使用的是Windows 7,可以使用下面的命令来设置 QTDIR 来安装目录。

  SETX QTDIR E:\\ Qt的

有关设置 PATH ,我强烈建议使用路径编辑器。在路径编辑器

 的Qt \\ BIN的目录添加到您的PATH

(不,如果它在系统路径或用户路径问题)

如果您preFER使用控制面板\\系统\\环境变量,那么你可以设置这些那里。

的Qt Visual Studio的外接

在这里你去,注销,登录或重新启动后,所有的Qt演示应用程序应该正常启动(我建议看看的斌\\ qtdemo.exe 的)。现在,您可以下载并安装Visual Studio插件(QT-VS-插件-1.1.9.exe)从Qt的下载页面,它会很好地工作。

附录A:官方说明:

有是在Qt的网站名为官方的wiki页面的Qt 4.7 Qt的安装视窗,但我发现它缺乏重要的信息。

参考


  

的Qt DevNet上论坛结果
  <一href=\"http://stackoverflow.com/questions/5587141/recommended-flags-for-minimalistic-qt-build\">Recommended一个简约的Qt标志建立结果
  构建Qt 4.5与Visual C ++ 2010 结果
  如何编译Qt的静态结果
  的Qt 4.7:配置Qt的结果选项
  编辑在搜索PATH环境变量
  窗户无痛苦 - op111.net


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.

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. In my case they compiled OK, but they produce runtime errors, like this:

or when started from 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. 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. 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. The only way to install the DebugCRT is to install the entirety of 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.

Downloading Qt

On http://qt.nokia.com/downloads, click LGPL.

Update: new link is here: http://qt-project.org/downloads

You should not download Qt by clicking "Qt libraries 4.7.2 for Windows (Visual Studio 2008, 218 MB)", but by clicking on the "zip" link above it.

On that link, you get a big zip file like "qt-everywhere-opensource-src-4.7.2.zip". Unzip this into a folder and make its path something nice and small, for example "E:\Qt"

Visual Studio Command Prompt

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). This is a special command prompt which has all the variables set for building with Visual Studio 2010 tools.

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. You can use the tab key for helping you with the directory names. When you have arrived at the correct directory, a dir command should return something like this.

Building Qt

Now it’s time for configure and build. For configuring a minimalist Qt, I'm using the following flags with 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.

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. It will take about 20-30 minutes with the above flags. 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. If you are on Windows 7, you can use the following command to set QTDIR to your installation dir.

setx QTDIR e:\Qt

For setting the PATH, I strongly recommend using Path Editor. 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.

Qt Visual Studio Add-in

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). 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.

Appendix A: Official Instructions:

There is a page at the official wiki at the Qt website called Qt 4.7 Installing Qt for Windows, but I found it lacking important information.

References

Qt DevNet forums
Recommended flags for a minimalistic Qt build
Building Qt 4.5 with Visual C++ 2010
How to compile Qt as static
Qt 4.7: Configure options for Qt
Edit the PATH environment variable in
Windows without pain - op111.net

这篇关于如何建立Qt的为Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆