Verifying your Qt setup on Unix


Summary
The following procedure will allow you to verify a working Qt configuration on Unix. It is critical that the developer successfully complete these steps before moving on to build a Qt application using ArcObjects or the C++ Qt samples.

Setting the Qt environment variables

The makefiles that Qt's qmake generates expects the environment variable QTDIR to point to the Qt installation directory. The C++ samples include makefiles that expect the variables QT3DIR (for Qt 3.3) or QT4DIR (for Qt 4.2) which should also point to your Qt installation directory. Since you'll be developing with ArcObjects it's not a bad idea to set these variables for both situations. For example:

% setenv QTDIR /usr/local/Trolltech/Qt-4.2.3 # For Qt makefiles
% setenv QT4DIR $QTDIR # For ArcObjects makefiles
 
In order to find the Qt tools and libraries it may also be necessary to prepend your PATH and LD_LIBRARY_PATH variables with $QTDIR/bin and $QTDIR/lib:
 
% setenv PATH $QTDIR/bin:$PATH
% setenv LD_LIBRARY_PATH $QTDIR/lib:$LD_LIBRARY_PATH
If you switch between Qt versions it will be necessary to reset these environment variables so the correct Qt version is accessible.

Build a "hello world" Qt sample application

Follow these steps to build a small "hello world" Qt application.
  1. Create the following C++ file in its own directory called hello.cpp. Specify the appropriate #include files for your Qt version:
[Qt C++]
// Qt 3.3
#include 
#include 
int main(int argc, char **argv)
{
  QApplication app(argc, argv);
  QLabel *label = new QLabel("Hello World!", 0);

  label->show();
  return app.exec();
}

// Qt 4.2
#include 
int main(int argc, char **argv)
{
  QApplication app(argc, argv);
  QLabel *label = new QLabel("Hello World!", 0);

  label->show();
  return app.exec();
}
  1. Run qmake to create a project file (a .pro file) and generate a makefile:
    % qmake -project -o hello.pro
    % qmake
  2. You may need to edit the Makefile's LIBS macro to link with the Qt libraries for your Qt version:

    # Qt 3.3:
    LIBS     = $(SUBLIBS) -L$(QTDIR)/lib -L/usr/X11R6/lib -lqt -lXext -lX11 -lm
    # Qt 4.2:
    LIBS     = $(SUBLIBS) -L$(QTDIR)/lib -L/usr/X11R6/lib -lQtCore -lQtGui -lXext -lX11 -lm
  1. Run make (on Solaris you may need to use GNU make):
    % make
The 'hello' sample should build and run without any errors. It will show a little window on your X server with a "Hello World!" label in it.
If this procedure is successful then you should be all set to build your Qt application. If you get any build errors check for typos in the CPP file and in the makefile. Also, make sure the QTDIR variable points to the correct Qt installation.