Developing with Qt using Visual Studio 2008 and NMake


Setting up your development environment

This document describes how to build an ArcGIS Engine C++ Qt application using either the Visual Studio IDE or the compiler from the command prompt with NMake. An application using the Qt control widgets is built in the same way as a command-line application, but with a few additional include and library settings. For an introduction to setting up the IDE or command prompt environment and creating a basic ArcGIS Engine C++ application, please refer to the following documents:
  • ArcGIS C++ development in the Visual Studio 2008 IDE
  • ArcGIS C++ development with nmake and the Windows command prompt
The remainder of this document contains instructions for configuring your build environment for use with the ArcGIS C++ Engine Qt control widgets, whether you are using the Visual Studio IDE or NMake at the command prompt. Sections specific to using NMake at the command prompt will be indicated with "(NMake)". Sections specific to the Visual Studio 2008 IDE will be indicated with "(IDE)".

Setting up your application

Setting up an ArcGIS Engine C++ Qt application is like setting up and ArcGIS Engine C++ application. There are only a few libraries, includes, and flags to add to your build.
First, in addition to the basic include paths, you will need to add the Qt include path to your project or NMakefile. This path may vary depending on your Qt installation, but they will probably be:
  • <QT_INSTALL_PATH>\include
You will need to replace "<QT_INSTALL_PATH>" with the location of your Qt installation. The following instructions assume that your Qt installation path is C:\Qt
(IDE) In your project settings, select Configuration Properties > C/C++. In the "Additional Include Directories" field, enter the required Qt include path. Additional paths should each be separated by a semicolon (";"). Your entry should resemble:
C:\Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI;C:\Program Files\ArcGIS\Engine10.0\com;C:\Qt\include
(NMake) You may wish to use the template Makefile included with ArcGIS Engine—Makefile.WindowsQt. It can be found in <install dir>/ArcGIS/DeveloperKit10.0/Samples/ArcObjectsCPP/MakefileTemplates. Using a text editor you will change the INCLUDEDIRS macro to the following:

    # Setting up the include directories
    INCLUDEDIRS = \
        /I "C:\Program Files\ArcGIS\DeveloperKit10.0\include\CPPAPI" \
        /I "C:\Program Files\ArcGIS\Engine10.0\com" \
        /I "C:\Qt\include"
    ...
    # Setting up the compiler options
    CPPFLAGS = /DESRI_WINDOWS $(INCLUDEDIRS) /nologo /GX
Next, you will need to add the necessary libraries and library paths to your build environment to support the Qt control widgets. The ArcGIS Engine runtime libraries:
  • qtctl.lib
    aoctl.lib
and their location (C:\Program Files\ArcGIS\DeveloperKit10.0\lib) and the Qt libraries:
  • qt-mt335.lib
and their location (C:\Qt\lib) must be added to the link directive. The Qt3 library that you use may have a different version than 3.3.5
(IDE) In your project settings, select Configuration Properties > Linker > General. In the "Additional Library Dependencies" field, enter the library paths, separated by a semicolon:
C:\Program Files\ArcGIS\DeveloperKit10.0\lib;C:\Qt\lib
In the project settings, select Configuration Properties > Linker > Input. In the "Additional Dependencies" field, enter the libraries, separated by spaces:
qtctl.lib aoctl.lib qt-mt335.lib
(NMake) Using again the template Makefile Makefile.WindowsQt, change the LINKFLAGS macro to the following:
    # Setting up the libraries and their paths
    LINKFLAGS = \
        /LIBPATH:C:\Program Files\ArcGIS\DeveloperKit10.0\lib \
        qtctl.lib aoctl.lib \
        /LIBPATH:C:\Qt\lib \
        qt-mt335.lib
Following these steps your Visual Studio 2008 IDE or NMake build environment should be ready to build your ArcGIS Engine C++ Qt application.

Compiling your application

Before compiling, make sure you have properly adjusted the project/program name, source files, and their dependencies as described in the documents:
  • ArcGIS C++ development in the Visual Studio 2008 IDE
  • ArcGIS C++ development with nmake and the Windows command prompt
(IDE) To compile an ArcGIS Engine application in Visual Studio 2008, click Build > Build Solution.
(NMake) Once Makefile.Windows is ready to compile your application, you can compile from the command line by typing 'nmake /f Makefile.Windows'.

Running your application

(IDE) Before you can run an ArcGIS Engine command line application from within Visual Studio 2005, you need to set up the arguments. Arguments are added to your program by customizing your project settings; go to the Project menu > Properties > Debugging item and add any arguments to 'Command Arguments'. Make sure the configuration you are working on is selected in the configuration combo box.
Finally, run the application by clicking Debug > Start Without Debugging or by pressing Ctrl+F5. If you wish to run the application in debug mode, click Debug > Start, or press F5.
(NMake) You can either invoke your application directly or through the makefile. If you choose to invoke it directly, you will need to provide command-line parameters from the command line. To use the makefile to run an ArcGIS Engine command-line application you must set up the command-line parameters in the makefile. Update your makefile to include variables for each input parameter and a run target.
An example of these modifications is shown below:
    # Setting up the program argument
    INPUT = C:\Data\inputfile
    ...
    # Setting up a run target
    run:
        $(PROGRAM) $(INPUT)
Once Makefile.Windows is ready for use with your application, you will be able to run from the command line by typing 'nmake /f Makefile.Windows run'.

A Note for Qt version 4

The include paths and libraries change for version 4 of Nokia's Qt toolkit. Replace your include paths with /I$(QT4DIR)/include /I$(QT4DIR)/include/Qt, where QT4DIR reflects either a Makefile macro or an environment variable set to your Qt 4 installation. Replace your library with QtCore.lib QtGui.lib. While your code for the ArcGIS Engine C++ Qt control widgets remains unchanged from Qt version 3, the code for Qt version 4 in general has changed slightly. Please refer to your Qt version 4 documentation to learn about transitioning your code from Qt version 3.