Introduction to Qt4

Qt4 is a cross-platform application framework that is widely used for developing application software with a graphical user interface (GUI) (in which cases Qt4 is classified as a widget toolkit), and also used for developing non-GUI programs such as command-line tools and consoles for servers. One of the major users of Qt is KDE4.

This package is known to build and work properly using an LFS-7.7-systemd platform.

Package Information

Additional Downloads

Qt Dependencies


Xorg Libraries



Cups-2.1.3, GTK+-2.24.30 (GTK+ 2 theme support), MariaDB-10.1.14 or MySQL, PostgreSQL-9.5.3, PulseAudio-8.0, and unixODBC-2.3.4

User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/qt4



The BLFS systemd development team is looking into archiving this package due to maintenance concerns and a GCC-6.x compatibility issue.

Qt Installation Alternatives

The installation of Qt presents several challenges and choices. Complicating the Qt installation is the fact that there are two versions, Qt4 and Qt5, that have executable programs with identical names. If both packages are installed on one system, the only methods to manage which set of programs is used is to either control the users' PATH or to rename files either directly or via symbolic links. Both packages cannot be installed in the same directory.

If you are only going to install one of the Qt versions, the choice of installation methods is easier. You can either install the components in the several directories of the /usr hierarchy or install the entire package in a separate directory of your choice. We refer to these options below as "Method 1: Installing in /usr" and "Method 2: Installing in /opt".

If both versions of Qt are to be installed, one or both versions need to be installed in a separate directory. For the purposes here we use the /opt directory. The selection of which version is being used by individual users on a system is controlled by the PATH variable. Other systems can be designed, but the BLFS editors find the PATH method easiest.

The advantage of installing in /usr is that no updates to the /etc/ld.so.conf or /etc/man_db.conf files are required. The package files are distributed within several subdirectories of the /usr hierarchy. This is the method that most commercial distributions use. The disadvantage for BLFS users is that this Qt instance cannot be upgraded while it is in use. For instance, it cannot be upgraded from a running KDE environment. It also precludes having multiple versions of Qt on your system and does not allow reverting to an existing, known working instance of Qt.

The advantage of installing Qt in a custom directory such as /opt/qt-4.8.7 or /opt/qt-5.6.0 or is that it keeps all the package files consolidated in a dedicated directory hierarchy. By using this method, an update can be made without overwriting a previous installation and users can easily revert to a previous version by changing one symbolic link or merely changing the PATH variable. It also allows a developer to maintain multiple versions of Qt4 or Qt5 for testing.

Setting the installation prefix

Installing in /opt/qt4

The BLFS editors recommend installing Qt4 in a directory other than /usr, ie /opt/qt4. To do this, set the following environment variable:

export QT4PREFIX=/opt/qt4


Sometimes, the installation paths are hardcoded into installed files. This is the reason why /opt/qt4 is used as installation prefix instead of /opt/qt-4.8.7. To create a versioned Qt4 directory, you may rename the directory and create a symlink:

mkdir /opt/qt-4.8.7
ln -sfnv qt-4.8.7 /opt/qt4

Later on, you may want to install other versions of Qt4. To do that, just remove the symlink and use /opt/qt4 as the prefix again. Which version of Qt4 you use depends only on where the symlink points.

Installation of Qt4



If Qt4 is being reinstalled into the same directory as an existing instance, run the commands done by root, such as make install, from a console or non-Qt4 based window manager. It overwrites Qt4 libraries that should not be in use during the install process.



If you did not install some of the recommended dependencies, examine ./configure --help output to check how to disable them or use internal versions bundled in the source tarball.



The build time and space required for the full Qt4 is quite long. The instructions below do not build the tutorials and examples. Removing the -nomake lines will create a complete build.



The BLFS editors do not recommend installing Qt4 into the /usr hierarchy because it becomes difficult to find components and to update to a new version. If you do want to install Qt4 in /usr, the directories need to be specified explicitly. In this case, set QT4PREFIX=/usr and add the following to the configure arguments below:

-bindir         /usr/bin/qt4                \
-plugindir      /usr/lib/qt4/plugins        \
-importdir      /usr/lib/qt4/imports        \
-headerdir      /usr/include/qt4            \
-datadir        /usr/share/qt4              \
-docdir         /usr/share/doc/qt4          \
-translationdir /usr/share/qt4/translations \
-demosdir       /usr/share/doc/qt4/demos    \
-examplesdir    /usr/share/doc/qt4/examples 

Install Qt4 by running the following commands:

./configure -prefix           $QT4PREFIX \
            -sysconfdir       /etc/xdg   \
            -confirm-license             \
            -opensource                  \
            -release                     \
            -dbus-linked                 \
            -openssl-linked              \
            -system-sqlite               \
            -no-phonon                   \
            -no-phonon-backend           \
            -no-webkit                   \
            -no-openvg                   \
            -nomake demos                \
            -nomake examples             \
            -optimized-qmake             &&

This package does not come with a test suite.

Now as the root user:

make install &&
rm -rf $QT4PREFIX/tests

Remove references to the build directory from the installed .pc files by running the following command:

find $QT4PREFIX/lib/pkgconfig -name "*.pc" -exec perl -pi -e "s, -L$PWD/?\S+,,g" {} \;

Remove references to the build directory in the installed library dependency (prl) files by running the following command as the root user:

for file in $QT4PREFIX/lib/libQt*.prl; do
     sed -r -e '/^QMAKE_PRL_BUILD_DIR/d'    \
            -e 's/(QMAKE_PRL_LIBS =).*/\1/' \
            -i $file

Building Qtwebkit

The bundled version of qtwebkit in the main package requires an obsolete version of the gstreamer package. To overcome this, we use a more recent version available separately.

To start, the upstream package is unusual in that it does not come in a directory, so we have to create one before unpacking the tarball. After that, we need to make the package compatible with the latest version of gcc and use an included script to actually complete the build. To do this, run the following instructions:

mkdir qtwebkit-2.3.4 &&
cd    qtwebkit-2.3.4 &&

tar -xf ../../qtwebkit-2.3.4.tar.gz             &&
patch -Np1 -i ../../qtwebkit-2.3.4-gcc5-1.patch &&

Tools/Scripts/build-webkit --qt --no-webkit2 --prefix=$QT4PREFIX

If desired, the build process can use parallel processors by adding the option --makeargs=-j<number> to the build-webkit instruction above.

To install the package, as the root user:

make -C WebKitBuild/Release install

Installing Auxillary Files

Install images and create the menu entries for installed applications. The QT4BINDIR variable is used here to point to the directory for the executable programs. If you have changed the bindir above, QT4BINDIR will need to be adjusted below. Be sure that the QT4BINDIR variable is defined in root's environment and as the root user:


install -v -Dm644 src/gui/dialogs/images/qtlogo-64.png \
                  /usr/share/pixmaps/qt4logo.png       &&

install -v -Dm644 tools/assistant/tools/assistant/images/assistant-128.png \
                  /usr/share/pixmaps/assistant-qt4.png &&

install -v -Dm644 tools/designer/src/designer/images/designer.png \
                  /usr/share/pixmaps/designer-qt4.png  &&

install -v -Dm644 tools/linguist/linguist/images/icons/linguist-128-32.png \
                  /usr/share/pixmaps/linguist-qt4.png  &&

install -v -Dm644 tools/qdbus/qdbusviewer/images/qdbusviewer-128.png \
                  /usr/share/pixmaps/qdbusviewer-qt4.png &&

install -dm755 /usr/share/applications &&

cat > /usr/share/applications/assistant-qt4.desktop << EOF
[Desktop Entry]
Name=Qt4 Assistant
Comment=Shows Qt4 documentation and examples

cat > /usr/share/applications/designer-qt4.desktop << EOF
[Desktop Entry]
Name=Qt4 Designer
Comment=Design GUIs for Qt4 applications

cat > /usr/share/applications/linguist-qt4.desktop << EOF
[Desktop Entry]
Name=Qt4 Linguist
Comment=Add translations to Qt4 applications

cat > /usr/share/applications/qdbusviewer-qt4.desktop << EOF
[Desktop Entry]
Name=Qt4 QDbusViewer
GenericName=D-Bus Debugger
Comment=Debug D-Bus applications

cat > /usr/share/applications/qtconfig-qt4.desktop << EOF
[Desktop Entry]
Name=Qt4 Config
Comment=Configure Qt4 behavior, styles, fonts

Some packages such as VLC-2.2.3 look for certain executables with a -qt4 suffix. Run the following command as the root user to create the necessary symlinks:

for file in moc uic rcc qmake lconvert lrelease lupdate; do
  ln -sfrvn $QT4BINDIR/$file /usr/bin/$file-qt4

Command Explanations

-confirm-license: Accept license without prompting user during configuration.

-opensource: Install the opensource version of Qt.

-release: This switch disables building with debugging symbols.

-nomake examples -nomake demos: These switches disable building programs that are only of interest to a developer using Qt.

-system-sqlite: This switch enables use the system version of SQLite.

-no-nis: This switch disables support for Network Information Service (NIS) which has been deprecated in recent versions of Glibc.

-no-phonon -no-phonon-backend: These switches disable building of the bundled Phonon library. Better version is provided by Phonon-4.8.3 package.

-dbus-linked -openssl-linked: These switches enable explicit linking of the D-Bus and OpenSSL libraries into Qt libraries instead of dlopen()-ing them.

-no-openvg: This switch disables OpenVG support in Qt.

-optimized-qmake: This switch enables building of the optimized qmake program.

-no-dbus: Use this switch if you don't have D-Bus installed.

Configuring Qt

Configuration Information

If you installed Qt in /usr, create an environment variable needed by certain packages. As the root user:

cat > /etc/profile.d/qt4.sh << EOF
# Begin /etc/profile.d/qt4.sh


# End /etc/profile.d/qt4.sh

If you installed Qt4 in a location other than /usr, you need to update the following configuration files so that Qt is correctly found by other packages and system processes.

As the root user, update the /etc/ld.so.conf file and the dynamic linker's run-time cache file:

cat >> /etc/ld.so.conf << EOF
# Begin Qt addition


# End Qt addition


As the root user, create the /etc/profile.d/qt4.sh file:

cat > /etc/profile.d/qt4.sh << EOF
# Begin /etc/profile.d/qt4.sh


pathappend $QT4DIR/bin           PATH
pathappend $QT4DIR/lib/pkgconfig PKG_CONFIG_PATH


# End /etc/profile.d/qt4.sh

Choosing Qt Program Versions

If you install both Qt4 and Qt5, you can use some simple scripts to select the currently active set of Qt programs. As the root user, create the following scripts:

cat > /usr/bin/setqt4 << 'EOF'
if [ "x$QT5DIR" != "x/usr" ]; then pathremove  $QT5DIR/bin; fi
if [ "x$QT4DIR" != "x/usr" ]; then pathprepend $QT4DIR/bin; fi
echo $PATH
cat > /usr/bin/setqt5 << 'EOF'
if [ "x$QT4DIR" != "x/usr" ]; then pathremove  $QT4DIR/bin; fi
if [ "x$QT5DIR" != "x/usr" ]; then pathprepend $QT5DIR/bin; fi
echo $PATH

You should now be able to use the appropriate Qt version by running source setqt4 or source setqt5 as desired. (Setting the PATH wont work in a subshell.) Another technique that can be used is to create appropriate alias additions to your ~/.bashrc like alias setqt4='source setqt4'.


Installed Programs: assistant, designer, lconvert, linguist, lrelease, lupdate, moc, pixeltool, qcollectiongenerator, qdbuscpp2xml, qdbus, qdbusviewer, qdbusxml2cpp, qdoc3, qhelpconverter, qhelpgenerator, qmake, qmlplugindump, qmlviewer, qt3to4, qtconfig, qttracereplay, rcc, uic3, uic, xmlpatterns, and xmlpatternsvalidator
Installed Libraries: libQtUiTools.a, libQt3Support.so, libQtCLucene.so, libQtCore.so, libQtDBus.so, libQtDeclarative.so, libQtDesignerComponents.so, libQtDesigner.so, libQtGui.so, libQtHelp.so, libQtMultimedia.so, libQtNetwork.so, libQtOpenGL.so, libQtScript.so, libQtScriptTools.so, libQtSql.so, libQtSvg.so, libQtTest.so, libQtWebKit.so, libQtXmlPatterns.so, and libQtXml.so, and several plugins under /opt/qt4/imports and /opt/qt4/plugins
Installed Directories: /usr/include/qt4, /usr/lib/qt4, /usr/share/doc/qt4, and /usr/share/qt4 OR /opt/qt4 and /opt/qt-4.8.7

Short Descriptions


is a tool for presenting on-line documentation.


is a full-fledged GUI builder. It includes powerful features such as preview mode, automatic widget layout, support for custom widgets, and an advanced property editor.


is part of Qt4's Linguist tool chain. It can be used as a standalone tool to convert and filter translation data files.


provides support for translating applications into local languages.


is a simple command line tool. It reads a Qt project file and produces message files used by the application.


reads a Qt project file, finds the translatable strings in the specified source, header and Qt Designer interface files, and produces or updates the translation files listed in the project file.


generates Qt meta object support code.


is a desktop magnifier and as you move your mouse around the screen it will show the magnified contents in its window.


is a tool used to create a Qt Help Collection.


takes a C++ source file and generates a D-Bus XML definition of the interface.


lists available services, object paths, methods, signals, and properties of objects on a bus.


is a graphical D-Bus browser.


is a tool that can be used to parse interface descriptions and produce static code representing those interfaces,


is a tool used by Qt Developers to generate documentation for software projects.


is a tool used to convert files to Qt help format.


is a tool used to generate a Qt compressed help file.


uses information stored in project files to determine what should go in the makefiles it generates.


is a tool to create a qmltypes file.


is a tool for loading QML documents that makes it easy to quickly develop and debug QML applications.


qt3to4 is a tool to help update Qt3 code to Qt4.


is used to customize the appearance of Qt applications.


is a tool to replay all drawing operations recording with -graphicssystem trace into a trace buffer.


is a resource compiler used in conjunction with designer.


is a Qt user interface compiler.


is a tool to generate Qt4 code out of user interface files generated by the Qt3 version of designer.


provides support for XPath, XQuery, XSLT, and XML Schema validation.


is a tool used to validate XML documents.

Last updated on 2016-05-07 15:10:29 -0500