Introduction to Qt
Qt is a cross-platform application
framework that is widely used for developing application software
with a graphical user interface (GUI) (in which cases Qt 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 KDE.
This package is known to build and work properly using an LFS-7.4
platform.
Package Information
Qt Dependencies
Required
alsa-lib-1.0.27.2 and MesaLib-9.2.0
Recommended
Certificate Authority
Certificates, D-Bus-1.6.14, GLib-2.36.4,
ICU-51.2 (unicode support), libjpeg-turbo-1.3.0, libmng-2.0.2, libpng-1.6.4,
LibTIFF-4.0.3, OpenSSL-1.0.1e, and SQLite-3.8.0.2
Optional
Cups-1.6.3, GTK+-2.24.20 (GTK+ 2 theme support),
gst-plugins-base-0.10.36 (For
QtWebKit HTML5 Video), MySQL-5.6.13, PostgreSQL-9.3.0, PulseAudio-4.0, unixODBC-2.3.1, and qtchooser-31
(runtime, if also installing Qt5 and installing in /usr)
User Notes: http://wiki.linuxfromscratch.org/blfs/wiki/qt4
Installation of Qt
There are several ways to install a complicated package such as
Qt. The files are not completely
position independent. Installation procedures execute the program
pkg-config to
determine the location of package executables, libraries, headers,
and other files. For Qt,
pkg-config will look
for the appropriate lib/pkgconfig/Qt*.pc
files which must be modified
if relocating the package. These files are set up correctly by the
build process.
The default installation places the files in /usr/local/qt/
. Many commercial distributions
place the files in the system's /usr
hierarchy. The package can also be installed in an arbitrary
directory.
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. It is also supported by the
optional qtchooser application.
The disadvantage of installing in /usr
is that the executable filenames for
Qt4 and Qt5 conflict if both packages are installed in
the same directory. The instructions below give a workaround for
this problem using the helper program qtchooser-31.
This requires renaming the Qt executables with a version suffix.
The advantage of installing Qt4 in
a custom directory such as /opt/qt-4.8.5
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.
Caution
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.
Warning
If Qt4 is being reinstalled into
the same directory as an existing instance, run the following
commands from a console or non-Qt4 based window manager. It
overwrites Qt4 libraries that
should not be in use during the install process.
Note
The build time and space required for the full Qt is quite long. The instructions below do
not build the tutorials and examples. Removing the -nomake
lines will create a
complete build.
Method 1: Installing in /usr
Install Qt4 by running the
following commands:
Note
If not also installing
Qt5 into the /usr directory,
change the entry for -bindir below to /usr/bin.
sed -i -e "/#if/d" -e "/#error/d" -e "/#endif/d" \
config.tests/unix/libmng/libmng.cpp &&
./configure -prefix /usr \
-bindir /usr/lib/qt4/bin \
-plugindir /usr/lib/qt4/plugins \
-importdir /usr/lib/qt4/imports \
-headerdir /usr/include/qt4 \
-datadir /usr/share/qt4 \
-sysconfdir /etc/xdg \
-docdir /usr/share/doc/qt4 \
-demosdir /usr/share/doc/qt4/demos \
-examplesdir /usr/share/doc/qt4/examples \
-translationdir /usr/share/qt4/translations \
-confirm-license \
-opensource \
-release \
-dbus-linked \
-openssl-linked \
-system-sqlite \
-no-phonon \
-no-phonon-backend \
-no-nis \
-no-openvg \
-nomake demos \
-nomake examples \
-optimized-qmake &&
make
This package does not come with a test suite.
Now, as the root
user:
make install &&
rm -rf /usr/tests &&
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
Remove references to the build directory from installed files by
running the following command as the root
user:
for file in 3Support CLucene Core DBus Declarative DesignerComponents \
Designer Gui Help Multimedia Network OpenGL Script \
ScriptTools Sql Svg Test UiTools WebKit XmlPatterns Xml
do
sed -i -e '/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/' \
/usr/lib/libQt${file}.prl
perl -pi -e "s, -L$PWD/?\S+,,g" /usr/lib/pkgconfig/Qt${file}.pc
done
unset file
If also installing Qt5 into /usr, symlink the Qt4 executables into /usr/bin
by running the following commands as the
root
user:
for file in /usr/lib/qt4/bin/*
do
ln -sfv ../lib/qt4/bin/$(basename $file) /usr/bin/$(basename $file)-qt4
done
Method 2: Installing in /opt/qt-4.8.5
This section provides an alternate way to install Qt4 by installing
almost all of the files in the /opt
directory. This allows management of all Qt4 related files in one
unit. For instance, a new version of Qt4 can be installed without
over-writing the existing installation and entire Qt4 instances can
be easily removed. However, it has the disadvantage of needing some
extra configuration.
Install Qt in /opt/qt-4.8.5 by
running the following commands:
sed -i -e "/#if/d" -e "/#error/d" -e "/#endif/d" \
config.tests/unix/libmng/libmng.cpp &&
export QTDIR=/opt/qt-4.8.5
./configure -prefix $QTDIR \
-sysconfdir /etc/xdg \
-confirm-license \
-opensource \
-release \
-dbus-linked \
-openssl-linked \
-system-sqlite \
-plugin-sql-sqlite \
-no-phonon \
-no-phonon-backend \
-no-nis \
-no-openvg \
-nomake demos \
-nomake examples \
-optimized-qmake &&
make
Now, as the root
user:
make install &&
ln -svfn qt-$VERSION /opt/qt &&
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
Remove references to the build directory from installed files by
running the following command as the root
user:
for file in 3Support CLucene Core DBus Declarative DesignerComponents \
Designer Gui Help Multimedia Network OpenGL Script \
ScriptTools Sql Svg Test UiTools WebKit XmlPatterns Xml; do
sed -i -e '/^QMAKE_PRL_BUILD_DIR/d;s/\(QMAKE_PRL_LIBS =\).*/\1/' \
$QTDIR/lib/libQt${file}.prl
perl -pi -e "s, -L$PWD/?\S+,,g" $QTDIR/lib/pkgconfig/Qt${file}.pc
done
unset file
Command Explanations
sed -i "..." ...:
This command fixes detection of libmng 2.0.
-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 Qt
developer.
-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.6.0 package.
-dbus-linkend
-openssl-linkend
: 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.
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/qt.sh << EOF
# Begin /etc/profile.d/qt.sh
QTDIR=/usr
export QTDIR
# End /etc/profile.d/qt.sh
EOF
If you installed Qt 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
/opt/qt/lib
# End Qt addition
EOF
ldconfig
As the root
user, create the
/etc/profile.d/qt.sh
file:
cat > /etc/profile.d/qt.sh << EOF
# Begin /etc/profile.d/qt.sh
QTDIR=/opt/qt
pathappend /opt/qt/bin PATH
pathappend /opt/qt/lib/pkgconfig PKG_CONFIG_PATH
export QTDIR
# End /etc/profile.d/qt.sh
EOF
For all methods, create the menu entries for installed
applications. As the root
user:
install -dm755 /usr/share/applications
cat > /usr/share/applications/qtconfig-qt4.desktop << "EOF"
[Desktop Entry]
Name=Qt4 Config
Comment=Configure Qt4 behavior, styles, fonts
Exec=qtconfig-qt4
Icon=qt4logo
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Settings;
EOF
cat > /usr/share/applications/assistant-qt4.desktop << "EOF"
[Desktop Entry]
Name=Qt4 Assistant
Comment=Shows Qt4 documentation and examples
Exec=assistant-qt4
Icon=assistant-qt4
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;Documentation;
EOF
cat > /usr/share/applications/designer-qt4.desktop << "EOF"
[Desktop Entry]
Name=Qt4 Designer
Comment=Design GUIs for Qt4 applications
Exec=designer-qt4
Icon=designer-qt4
MimeType=application/x-designer;
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;
EOF
cat > /usr/share/applications/linguist-qt4.desktop << "EOF"
[Desktop Entry]
Name=Qt4 Linguist
Comment=Add translations to Qt4 applications
Exec=linguist-qt4
Icon=linguist-qt4
MimeType=text/vnd.trolltech.linguist;application/x-linguist;
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;
EOF
cat > /usr/share/applications/qdbusviewer-qt4.desktop << "EOF"
[Desktop Entry]
Name=Qt4 QDbusViewer
GenericName=D-Bus Debugger
Comment=Debug D-Bus applications
Exec=qdbusviewer-qt4
Icon=qdbusviewer-qt4
Terminal=false
Encoding=UTF-8
Type=Application
Categories=Qt;Development;Debugger;
EOF