Home > Articles > Programming > C/C++

C++ GUI Programming with Qt4: Obtaining and Installing Qt

  • Print
  • + Share This
This appendix explains how to obtain and install a GPL edition of Qt onto your system.
This chapter is from the book

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.

Installing Qt/Windows

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.

Installing Qt/Mac

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

Installing Qt/X11

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.

  1. Change directory to the directory where you downloaded the archive file. For example:
    cd /tmp
  2. 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.

  3. 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

    You can run ./configure -help to get a list of configuration options.

  4. To build Qt, type


    This will create the library and compile all the demos, examples, and tools. On some systems, make is called gmake.

  5. 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:

    make install
  6. 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:

    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.

  • + Share This
  • 🔖 Save To Your Account

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020