A. Obtaining and Installing Qt
- A Note on Licensing
- Installing Qt/Windows
- Installing Qt/Mac
- Installing Qt/X11
This appendix explains how to obtain and install a GPL edition of Qt onto your system. Editions are available for Windows, Mac OS X, and X11 (for Linux and most versions of Unix). The pre-built binaries for Windows and Mac OS X include SQLite, a public domain in-process database, together with a SQLite driver. The versions built from source can include SQLite at your option. To begin, download the latest version of Qt from http://www.trolltech.com/download/. If you plan to develop commercial software, you will need to buy a commercial edition, and when you get it you should follow the installation instructions that are provided.
Trolltech also provides Qt/Embedded Linux for building applications for Linux-based embedded devices such as PDAs and mobile phones. If you are interested in creating embedded applications, you can obtain Qt/Embedded Linux from Trolltech's download web page.
The example applications used in this book are available from the book's web site, http://www.informit.com/title/0132354160. In addition, Qt provides many small example applications located in the examples subdirectory.
A Note on Licensing
Qt is available in two forms: open source and commercial. The open source editions are available free of charge; the commercial editions can be purchased for a fee.
If you want to distribute the applications that you create with an open source edition of Qt, you must comply with the specific terms and conditions laid down in the licenses for the software you use to create the applications. For open source editions, the terms and conditions include the requirement to use the GNU General Public License (GPL). Open licenses such as the GPL give the applications' users certain rights, including the right to view and modify the source and to distribute the applications (on the same terms). If you want to distribute your applications without source code (to keep your code private) or if you want to apply your own commercial license conditions to your applications, you must buy commercial editions of the software you use to create the applications. The commercial editions of the software allow you to sell and distribute your applications on your own terms.
The full legal texts of the licenses are included with the GPL versions of Qt for Windows, Mac OS X, and X11, along with information on how to obtain commercial versions.
At the time of this writing, the Windows installer was called qt-win-opensource-4.3.2-mingw.exe. The version number will probably be different by the time you read this, but the process should be the same. Download the file and run it to begin the installation process.
When the installer reaches the MinGW page, if you already have the MinGW C++ compiler, you must specify the directory where it is located; otherwise, check the checkbox and have the installer install MinGW for you. The GPL version of Qt will not work with Visual C++, so if you do not have MinGW already installed, you will need to install it. Qt's standard examples are automatically installed, along with the documentation.
If you choose to install the MinGW compiler, there may be a small delay between the completion of the MinGW installation and the start of the Qt installation.
After installation, you will have a new folder in the Start menu called Qt by Trolltech v4.3.2 (OpenSource). This folder has shortcuts to Qt Assistant and Qt Designer, and also one called Qt 4.3.2 Command Prompt that starts a console window. When you start this window it will set the environment variables for compiling Qt programs with MinGW. In this window, you can run qmake and make to build Qt applications.
Before Qt can be installed on Mac OS X, Apple's Xcode Tools must already be installed. The CD (or DVD) containing these tools is usually supplied with Mac OS X; they can also be downloaded from the Apple Developer Connection, http://developer.apple.com/.
If you have Mac OS X 10.4 and Xcode Tools 2.x (with GCC 4.0.x) or later, you can use the installer described shortly. If you have an earlier version of Mac OS X, or an older version of GCC, you will need to install the source package manually. This package is called qt-mac-opensource-4.3.2.tar.gz and is available from Trolltech's web site. If you install this package, follow the instructions in the next section for installing Qt on X11.
To use the installer, download qt-mac-opensource-4.3.2.dmg. (This version was correct at the time of this writing, but it will probably be different by the time you read this.) Double-click the .dmg file, and then double-click the package called Qt.mpkg. This will launch the installer, which will install Qt in /Developer, along with its documentation and the standard examples.
To run commands such as qmake and make, you will need to use a terminal window, for example, Terminal.app in /Applications/Utilities. It is also possible to generate Xcode projects using qmake. For example, to generate an Xcode project for the hello example, start a console such as Terminal.app, change to your examples/ chap01/hello directory, and enter the following command:
qmake -spec macx-xcode hello.pro
Download the file qt-x11-opensource-src-4.3.2.tar.gz from Trolltech's web site. (This version was correct at the time of this writing, but it will probably be different by the time you read this.) To install Qt in its default location on X11, you will need to be root. If you do not have root access, use configure's -prefix option to specify a directory to which you have permission to write.
- Change directory to the directory where you downloaded the archive file. For example:
Unpack the archive file:
gunzip qt-x11-opensource-src-4.3.2.tar.gz tar xvf qt-x11-opensource-src-4.3.2.tar
This will create the directory /tmp/qt-x11-opensource-src-4.3.2. Qt requires GNU tar; on some systems it is called gtar.
Execute the configure tool with your preferred options to build the Qt library and the tools supplied with it:
cd /tmp/qt-x11-opensource-src-4.3.2 ./configure
You can run ./configure -help to get a list of configuration options.
To build Qt, type
This will create the library and compile all the demos, examples, and tools. On some systems, make is called gmake.
To install Qt, type
su -c "make install"
and enter the root password. (On some systems, the command is sudo make install.) This will install Qt into /usr/local/Trolltech/Qt-4.3.2. You can change the destination by using the -prefix option with configure, and if you have write access to the destination you can simply type:
Set up certain environment variables for Qt.
If your shell is bash, ksh, zsh, or sh, add the following two lines to your .profile file:
PATH=/usr/local/Trolltech/Qt-4.3.2/bin:$PATH export PATH
If your shell is csh or tcsh, add the following line to your .login file:
setenv PATH /usr/local/Trolltech/Qt-4.3.2/bin:$PATH
If you used -prefix with configure, use the path you specified instead of the default path shown here.
If you are using a compiler that does not support rpath, you must also extend the LD_LIBRARY_PATH environment variable to include /usr/local/ Trolltech/Qt-4.3.2/lib. This is not necessary on Linux with GCC.
Qt comes with a demo application, qtdemo, that shows off many of the library's features. It serves as a nice starting point to see what Qt can do. To see Qt's documentation, either visit http://doc.trolltech.com/ or run Qt Assistant, Qt's help application, invoked by typing assistant in a console window.