• 49406阅读
  • 1回复

Qt4 with Visual Studio [复制链接]

上一主题 下一主题
离线andy212
 

只看楼主 倒序阅读 楼主  发表于: 2006-04-21
Qt4 with Visual Studio
Qt4 with Visual Studio

注意:虽然用vc6.0的编译器也能生成QT,但只能在命令行模式下使用(nmake),不能够结合vc6.0的IDE一块使用(虽然能生成.dsp文件,但是却用不了。我试过很多次,都用不了,不知道各位怎么样?)。没办法,我就装了vc.net2003试试,没想到还挺顺利的:-)
现在把编译的过程介绍如下,大部份都是转载的,只是修改了很小一部分。
From qtnode
Contrary to popular belief, you can use Qt4 with Visual Studio to create Open Source software.

These instructions are for Qt 4.1.2. 对于Qt的其他版本,方法类似,只是要下载相应的补丁。补丁见附件!

Contents

1 Building Qt
1.1 Obtain and install the Qt source
1.2 Download and install the patch allowing Qt to be compiled with Visual Studio compilers
1.3 Open a command prompt in the Qt source directory
1.4 Patching the Qt sources
1.5 Configuring your Qt install (and building qmake)
1.6 Building the Qt library
2 Setting up your environment
3 Testing your install
4 Creating Visual Studio projects
5 Maintaining Visual Studio Projects
6 Additional Info



Building Qt
注意:
1.对于Windows Server 2003 来说,要先下载 Windows® Server 2003 R2 Platform SDK (不知道别的操作系统怎样?)
2.设置相应的环境变量path, lib, include.具体环境变量的设置,可以看 http://www.cs.usask.ca/grads/wew036/latex/env.html 。我设成了:

path:
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Qt\4.1.1-msvc.net\bin

lib:
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Lib\;C:\Qt\4.1.1-msvc.net\lib;C:\WINDOWS\system32;c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Lib

include:
C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\;C:\WINDOWS\system32;C:\Qt\4.1.1-msvc.net\include;c:\Program Files\Microsoft Platform SDK for Windows Server 2003 R2\Include

Obtain and install the Qt source


To start, download the source package: Download Qt (Be sure to download the source package, not the package that installs MinGW. The source package is a .zip file, whereas the binary package for use with MinGW is an executable.)


Unzip your Qt source to a logical location.
Here are some suggestions:
  C:\Qt\4.1.2\
  C:\Qt\4.1.2-msvc2003\   (<-- if for instance you plan on using Visual Studio 2003)


Download and install the patch allowing Qt to be compiled with Visual Studio compilers
Download Image:Qtnode-acs-qt4.1.2.zip


Unzip the contents of qtnode-acs-qt4.1.2.zip and place all of the files contained in the qt-node-acs-qt4.1.2 directory into the directory that you have unzipped the Qt sources.


Open a command prompt in the Qt source directory
Run cmd.exe however you prefer, but you must make sure that the Visual Studio compiler files are in your path.

If you are using Microsoft Visual Studio 6.0, try running vcvars32.bat from the command-line.
If you are using Microsoft Visual Studio .NET or 2005, go into the program group called 'Visual Studio Tools' and run the command prompt shortcut.



A simple way to ensure your environment is setup properly is to use to see if nmake.exe is in your path:
C:\Qt\4.1.2> nmake /?

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: NMAKE @commandfile
    NMAKE [options] [/f makefile] [/x stderrfile] [macrodefs] [targets]

Options:

....Once you are sure that you have the Visual Studio compiler in your path and you're at the command prompt in the Qt source directory, you are ready to proceed.

[edit]Patching the Qt sources
If you have installed the patch files from qtnode-acs-qt4.1.2.zip correctly, then you should be able to patch the Qt sources by running:
C:\Qt\4.1.2> installpatch412.batYou should see a lot of action, which is normal, which shows all of the files that are being patched:
C:\Qt\4.1.2> installpatch412.bat
patching file qconfigure.bat
patching file examples/threads/waitconditions/waitconditions.pro
patching file misc/bcc32pch/Makefile.win32-borland
patching file misc/bcc32pch/bcc32pch.cpp
patching file misc/bcc32pch/bcc32pch.pri
patching file misc/bcc32pch/bcc32pch.pro
patching file mkspecs/win32-bccx/qmake.conf

  [snip]

patching file tools/porting/src/rpptreeevaluator.cpp
patching file tools/porting/src/rpptreewalker.cpp
patching file tools/porting/src/src.pro
Press any key to continue . . .
Now run qconfigure.batYou are now ready for the next step: configuring your Qt install.

Configuring your Qt install (and building qmake)
We will not use the standard configure.exe that ships with Qt. We will use qconfigure.bat, included with the qtnode-acs-qt4.1.2.zip file.

But, if you are not sure about which options you want, run configure.exe with the --help option:
configure.exe --helpA list of options will be displayed. Take note of any options that you are interested in. Note that by default, static and debug versions of the library are built - this is usually the appropriate choice for most developers.

Once you have written down (or mentally noted) which options you will use, we will run qconfigure.bat. It will in turn call configure.exe with your chosen options.

qconfigure.bat requires as the first parameter, one of the following compiler choices:

msvc   <- if you are using Visual Studio 6.0
msvc.net   <- if you are using Visual Studio .NET (2003)
msvc2005   <- if you are using Visual Studio 2005



After the first option, you can pass qconfigure.bat any of the configure.exe you had previously noted. For instance you might type:
C:\Qt\4.1.2> qconfigure.bat msvc.net(注意此处:debug版和release版均生成)

(This command would produce only the release libraries and would exclude STL support in Qt.)

(Note that if you want to build static libraries instead of shared, see Building static)

You will be prompted 3 times while running qconfigure.bat:

You will be asked to accept the GPL license. Type 'y' followed by <Enter> to continue.
You will then be informed that qmake is about to be built. Type 'y' followed by <Enter> to continue. This will take a few moments.
You will then be informed that the Makefiles will be generated. Type 'y' followed by <Enter> to continue. This will be a short operation.
Once qconfigure.bat has finished, you will be presented with the following message:
====================================================

You are now ready to build Qt (msvc2005)

If you specified -static, type 'nmake sub-src'
          otherwise, type 'nmake'

To start over, type 'nmake distclean'
and then re-run qconfigure.bat

====================================================

Building the Qt library
Once configuration and building qmake are completed, you are now ready to build the library. Simply run nmake:
C:\Qt\4.1.2> nmakeQt takes a long time to compile. Now is a good time to brew a pot of coffee.

(If you have specified -static as one of your configuration options, see Building static)

Setting up your environment
There are multiple approaches to this, but this is a foolproof way to ensure that your newly create Qt libs are usable.

Prepend the Qt bin directory to your PATH. Depending on where you installed your Qt sources, the full path may be similar to:

C:\Qt\4.1.2\bin
C:\Qt\4.1.2-msvc2003\bin
C:\Qt\4.1.2-visual-studio\bin
Ensure that the QMAKESPEC environment variable is set to the appropriate value.

If you use Visual Studio 6.0, then win32-msvc is the correct value.
If you use Visual Studio .NET (2003), then win32-msvc.net is the correct value.
If you use Visual Studio 2005, then win32-msvc2005 is the correct value.
(Note: this is the recommended practice from qtnode. You can use Qt in other ways with different settings, but this way is foolproof.)

To set your environment variables in Windows, please see http://www.cs.usask.ca/grads/wew036/latex/env.html

Note that you may have to re-open a command window before your settings are changed.

To check that your PATH is set correctly:
C:\> qmake -v
QMake version: 2.00a
Using Qt version 4.1.2 in C:\Qt\4.1.2\libTo see if QMAKESPEC is set correctly:
C:\> echo %QMAKESPEC%
win32-msvc.net

Testing your install
Please test your install from the command-line first. Follow the http://qtnode.net/wiki/Hello_World]Hello World instructions.

Creating Visual Studio projects
{Note: The following works with MS Visual Studio 2005 and 2003, and has not been tested on other versions - look for an expanded section of this section later}


To create a project, use the -t and -o options.

Normally, (as in the Hello World example), you would simply type:

prompt> qmake -project
prompt> qmake
To create a .vcproj which will be used by Visual Studio, we will type:

prompt> qmake -project -t vcapp -o projectname.pro
prompt> qmakeIn the first command above, projectname.pro is the desired name of your project file. Be sure to include the extension .pro with your project file name. If the above command is executed as written in a directory that includes source files (either in that directory or in a subdirectory of that directory), a new Visual Studio project file is created:

projectname.vcproj
You can double-click on this vcproj file, or simply type its name in the command window and Visual Studio will create an associated .sln file.

The -t option was used to specify the template used by qmake. By default, the template is app. The app template creates Makefiles which can be used on the command-line when running nmake. But since we are interest in using the Visual Studio IDE, we want a vcapp which will give us a .vcproj instead of a regular Makefile.

Note that you can also use the -tp vc option instead of -t vcapp. This will prepend vc to the default template (which is normally app).

Maintaining Visual Studio Projects
To add files to your project, you can edit your .pro file and re-run qmake. The only problem is that any customizations to your .sln will be lost when you open up the newly updated .vcproj

Is this true? can someone confirm this? Is there a better way to deal with both .pros and .slns?

Additional Info
This set of patches has been altered from the Q../Free project. Original download available at: http://sourceforge.net/project/showfiles.php?group_id=49109

The changes that were made are:

the patch file was altered to work with Qt 4.1.2 (patch was originally for 4.1.0)
qconfigure.bat was altered as follows:
User can stop execution before building qmake
User can stop execution before generating Makefiles
Does not automatically call nmake for you. (This is important because if you specify the -static option, you need to be able to run nmake sub-src)
A check was added for qmake\tmp (when not present this is a problem for some users)
Retrieved from "http://qtnode.net/wiki/Qt4_with_Visual_Studio"
[ 此贴被andy212在2006-04-21 23:06重新编辑 ]
描述:acs4qt411p1.zip
附件: acs4qt411p1.zip (154 K) 下载次数:163
描述:acs4qt412p1.zip
附件: acs4qt412p1.zip (154 K) 下载次数:188
离线cauc_dg
只看该作者 1楼 发表于: 2006-10-27
两个小时。。。QT是出来了,但后面的hello程序产生不了.net的.vcproj啊,没反应,这是怎么个一回事捏?
每天进步一点点
快速回复
限100 字节
 
上一个 下一个