He,YuanHui —— 业精于勤荒于嬉,行成于思毁于随

如果你喜欢一个事,又有这样的才干,那就把整个人都投入进去,就要象一把刀直扎下去直到刀柄一样,不要问为什么,也不要管会碰到什么。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


Creating New Qt Projects

Once you have installed the add-in, Visual Studio's New Project dialog will contain a Qt Projects folder with the following project templates:

  1. Qt Application: A simple Qt GUI Application with one form.
  2. Qt Console Application: A basic Qt console application.
  3. Qt Library: A basic Qt-based dynamic library.
  4. Qt4 Designer Plugin: A Qt Designer custom widget plugin.
  5. ActiveQt Server: A simple ActiveX server.

If you have a Qt for Windows CE license, two additional project types are available:

  1. Qt WindowsCE Application: A simple Qt GUI Application for Windows CE with one form.
  2. Qt WindowsCE Library: A basic Qt-based dynamic library for Windows CE.

Each Qt project provides a wizard that allows you to specify the Qt modules required for your project. For some projects, the wizard will also generate a skeleton class that you can use to get started.

If you have used the installer for the binary version of Qt, you are now ready to write Qt code and build your projects. Alternatively, if you have built Qt from source, then you must tell Visual Studio where to find Qt. This step is further explained in the Basic Qt Version Management section.

Modifying Project Properties

Qt related project properties can be modified by opening the Qt Project Settings dialog. To display this dialog, select the respective Qt project in the solution explorer and select Qt|Qt Project Settings.

Screenshot of the property browser when selecting a Qt project

The following Qt project settings can be changed:

PropertyDescription
VersionThe Qt version to use for this project (see Basic Qt Version Management).
MocDirectoryThe directory (relative to the project) where the generated moc files are put. This directory must include the $(ConfigurationName) variable, to ensure that the moc files for different configurations (e.g., debug or release) do not collide.
MocOptionsAdditional command line options for the moc build step.
UicDirectoryThe directory (relative to the project) where the uic generated header files are put.
RccDirectoryThe directory (relative to the project) where the rcc generated source files are put.

When a Qt project is created, these properties are initialized to default values based on the last entered information found in the the Qt|Qt Project Settings dialog.

Basic Qt Version Management

The Visual Studio Add-in offers its own simple Qt version management, enabling you to use multiple versions of Qt 4 in parallel, e.g., Qt 4.5.0 and 4.5.1. When you install the add-in, the information about Qt versions is added to the user registry hive. So, another user will have to add a new Qt version since no default version will be set.

To add or remove Qt versions, click Qt|Configure Qt Versions and select the Qt Versions page. Click Add, then enter a name for the Qt version and the path to Qt's root directory, for example,C:\\Qt\\4.5.0". The first added Qt version is automatically the default version which will be used when creating new projects or importing a project from a .pro file. The default versions for Qt Windows or Windows CE projects can be changed using the combo boxes located under the Qt Builds list.

Screenshot of Qt versions configuration dialog

To specify which Qt version a project should use, select the project node of a Qt project (e.g., "Project1") in the Solution Explorer, and set its Version property using the Qt Project Settings.

Changing the Qt version for all projects in the solution can be done by invoking the context menu of the solution and activating the Change Solutions' Qt Version item. You can then select your desired Qt version in the dialog listing all available Qt versions.

Note: When you set a Qt version for the solution, this version becomes the default version if you add new projects to the solution.

Using the Qt Visual Studio Add-in does not require a globally set Qt environment variable. The Add-in will always overwrite the existing global Qt environment variable.

Note: If the build of your Qt projects fails with the error message The following environment variables were not found: $(QTDIR), then the project is probably referencing an invalid Qt build. This can happen after uninstalling an old Qt version. To correct this, change the Qt version of your project to a valid one.

Changing The Target Platform of Your Project

If you are developing on the Windows CE platform, Visual Studio Add-in enables you to switch between Windows and Windows CE easily. It is possible to create a standard Windows project, develop and test your application on your desktop PC, then later convert it into a Qt on Windows CE version.

To switch between platforms choose the appropriate Qt version in the Version property using the property browser, as described above.

Importing and Exporting Projects

Qt and Visual Studio use different file formats to save projects. If you build your application on multiple platforms, you probably already use Qt .pro files with qmake; otherwise, you might use .vcproj files and Visual Studio to build your project, usually convenient for Windows- only development.

Qt's Visual Studio add-in provides a way to combine both approaches - you do not have to manually maintain .pro files and .vcproj files in parallel. You start by creating a .vcproj file as usual. When you want a qmake .pro file, select Qt|Create Basic .pro File to generate a .pro file where you can store Unix and/or Mac OS X specific settings.

Screenshot of export dialog

If you have multiple Qt projects in one Visual Studio solution, the basic .pro file generator can create a master .pro file of type subdirs that includes all of the projects.

The generated .pro file is not meant to be a complete file, but a simple starting point for porting to other platforms. Having said, these files should be sufficient for compiling the skeleton projects created by the predefined Qt project wizards. The .pro file includes a .pri file.

The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project. To generate the .pri file, select Qt|Export Project to .pri File. Whenever you add or remove a file from the Visual Studio project file, you must regenerate the .pri file to ensure that the application can still be build on other platforms.

Also, ensure that the included .pri file in the .pro file points to the right file. If you saved the .pri file in the suggested path and name, this should be correct.

Developers on platforms other than Windows can add or remove files to the project by editing the .pri file. When this happens, Windows developers must select Qt|Import .pri File to Project to bring the Visual Studio project file in sync with the .pri file.

If your project contains platform-specific source files, these files should be listed in the .pro file so that they are not overwritten by the Visual Studio Add-in.

In summary, a cross-platform Qt project consists of the following files:

  • .vcproj file containing Windows-specific settings and listing the files in the project.
  • .pro file containing Unix and/or Mac OS X specific settings.
  • .pri file (a qmake include file) listing the files in the project.

If you already have a .pro file but not a .vcproj file, select Qt|Open Qt Project File (.pro)... to convert your .pro file to a .vcproj file. Be aware that the generated .vcproj only contains Windows-specific settings. Also, there is no way to convert a .vcproj file back to a .pro file format, apart from the basic .pro mechanism described above.

 

posted on 2010-07-03 18:08  He,YuanHui  阅读(1395)  评论(0编辑  收藏  举报

Add to Google