Guidelines and HOWTOs/Build from source/OwnQt5: Difference between revisions

From KDE Community Wiki
(Update general structure to have better distinction between self compiled and distro packages)
(Update the path to build-include file)
 
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
= Use Qt 5 for Development =
{{Note|This page is archived. See page history.}}


[http://qt.io/ Qt] is the base of mostly all KDE software. Thus, when developing any KDE application or framework, you require Qt. For this, either you can use development packages by your distribution or compile Qt yourself. Note that using Qt development packages often is the more convenient way. If the Qt version provided by your distribution is recent enough (in terms of version, features and bug fixes) and you do not have any specific reason to do otherwise, [[#Use Qt5 Distribution Packages|use Qt distribution packages]].
= Use Qt5 for Development =
 
[http://qt.io/ Qt] is the base of mostly all KDE software. Thus, when developing any KDE application or framework, you require Qt. For this, either you can use development packages by your distribution or the Qt company or compile Qt yourself. Note that using Qt development packages often is the more convenient way. If the Qt version provided by your distribution is recent enough (in terms of version, features and bug fixes) and you do not have any specific reason to do otherwise, [[#Use Qt5 Distribution Packages|use Qt distribution packages]].
 
If you still want to compile Qt from source, the recommended way to do it is [[Get_Involved/development|using kdesrc-build]]. This also makes sure that you use the version of the Qt framework recommended by the KDE community, i.e. the [[Qt5PatchCollection|KDE Qt patch collection]].
 
The rest of this page is old content.


== Build Qt5 from Sources ==
== Build Qt5 from Sources ==
In the following, we explain how to build Qt5 from  sources. Choose one of the following sections to get your Qt setup. If you build Qt with the intention to actually develop Qt patches then you should go for a full debug build. If you merely need Qt to develop KDE applications then you should go for the release with debug symbol version.
In the following, we explain how to build Qt5 from  sources. Choose one of the following sections to get your Qt setup.
# '''Full Debug Build:''' If you build Qt with the intention to actually develop Qt patches then you should go for a full debug build.
#* '''Pro:''' full control and debugging capabilities
#* '''Contra:''' takes long to compile on the first time, might be an additional source of errors for beginners
# '''Release Build:''' If you merely need Qt to develop KDE applications then you should go for the release with debug symbol version.
#* '''Pro:''' This build is the most ideal build when developing applications and tuning performance. It has the speed of a release build but with debug symbols which give you more information in for example kcachegrind with data collected through valgrind.
#* '''Contra:''' The Qt libraries will be quite a lot bigger due to the debug symbols.


{{Note|<b>ArchLinux users</b>: qtwebkit and qtwebengine use Python to generate some files, but they use Python 2.x syntax. So you have to make ''python'' pointing to ''/usr/bin/python2'', to do that see the [https://wiki.archlinux.org/index.php/Python#Python_2 Arch Wiki].}}
Note that it is not officially supported to build just individual frameworks (though it works). This might be caused by limited time or disk space and hence you just want to build some of Qt5. In this case, you could restrict yourself to separate checkouts of qtbase.git, qtsvg.git, qtx11extras.git, qtscript.git and qttools.git. This is enough to build  frameworks/* (but not enough for e.g. plasma-framework).


==== Qt5 full debug build ====
Both instructions contain the following steps, only the configure-step differs.
* PRO: full control and debugging capabilities
==== Required Tools ====
* CON: takes long to compile on the first time, might be an additional source of errors for beginners
You need the following tools:
* Git
* Perl
* Python


To build all of qt5 execute:
==== Initial Clone of the Qt5 Repository ====
To clone the required sources to build all of Qt5 execute:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
git clone git://code.qt.io/qt/qt5.git --branch 5.5
git clone git://code.qt.io/qt/qt5.git --branch 5.5
</syntaxhighlight>
==== Configure and Build: Variant 1 (Full Debug Build) ====
<syntaxhighlight lang="bash">
cd qt5
cd qt5
./init-repository
./init-repository
Line 22: Line 42:
</syntaxhighlight>
</syntaxhighlight>


==== Configure and Build: Variant 2 (Release Build) ====
<syntaxhighlight lang="bash">
cd qt5
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples -dbus \
  -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -release -force-debug-info -reduce-relocations \
  -optimized-qmake
make
</syntaxhighlight>
==== Later Update of the Qt5 Repository ====
To update qt5 later:
To update qt5 later:
<syntaxhighlight  lang="bash">
<syntaxhighlight  lang="bash">
Line 36: Line 67:
</syntaxhighlight>
</syntaxhighlight>


Experimental and not officially supported: if you don't have enough time and disk space for all of qt5, you could restrict yourself to separate checkouts of qtbase.git, qtsvg.git, qtx11extras.git, qtscript.git and qttools.git, this is enough to build  frameworks/* (but not enough for plasma-framework).
==== Distribution Specific Notes ====
 
{{Note|<b>ArchLinux users</b>: qtwebkit and qtwebengine use Python to generate some files, but they use Python 2.x syntax. So you have to make ''python'' pointing to ''/usr/bin/python2'', to do that see the [https://wiki.archlinux.org/index.php/Python#Python_2 Arch Wiki].}}
==== Qt5 release with debug symbols build ====
* PRO: This build is the most ideal build when developing applications and tuning performance. It has the speed of a release build but with debug symbols which give you more information in for example kcachegrind with data collected through valgrind.
* CON: The Qt libraries will be quite a lot bigger due to the debug symbols.


To build all of qt5 execute:
==== Qt based libraries ====
<syntaxhighlight lang="bash">
You'll probably want to also compile your own Qt-based dependencies of KDE software, like poppler or libaccounts-qt to avoid mixing your Qt with the distro Qt. To do this, add this line to your kdesrc-buildrc
git clone git://code.qt.io/qt/qt5.git --branch 5.5
<syntaxhighlight lang="cfg">
cd qt5
include extragear/utils/kdesrc-build/data/build-include/custom-qt5-libs.ksb
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples -dbus \
  -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -release -force-debug-info -reduce-relocations \
  -optimized-qmake
make
</syntaxhighlight>
</syntaxhighlight>


== Use Qt5 Distribution Packages ==
== Use Qt5 Distribution Packages ==
* PRO: faster to get started, one source of errors less
* '''Pro:''' faster to get started, one source of errors less
* CON: usually doesn't have debug symbols. Great for developing applications and measuring performance. Not so great for tuning performance (you'd need debug symbols for that).
* '''Contra:''' usually doesn't have debug symbols. Great for developing applications and measuring performance. Not so great for tuning performance (you'd need debug symbols for that).


Note that the Qt version currently must be '''>= 5.5'''
Note that the Qt version currently must be '''>= 5.5'''
Line 71: Line 94:


===== Debian =====
===== Debian =====
* For now, Qt >= 5.5 can only be found in experimental repository. If it's not already the case, add it to your sources list and update : 
New major releases (those with a .0 suffix) are usually skipped from Debian/testing, but often provided via experimental. To get packages from experimental you should know what you do (acting on your own risk ;) ) and add the following line to your /etc/apt/sources.list file.
<pre  style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
$ sudo sh -c "echo 'deb http://ftp.debian.org/debian experimental main' >> /etc/apt/sources.list"
$ sudo apt-get update


* If you have key warnings, you can install them with
<syntaxhighlight lang="bash">
$ gpg --keyserver pgpkeys.mit.edu --recv-keys 8B48AD6246925553
sudo sh -c \
$ gpg -a --export 8B48AD6246925553 | sudo apt-key add -
"echo 'deb http://ftp.debian.org/debian experimental main' \
$ gpg --keyserver pgpkeys.mit.edu --recv-keys 7638D0442B90D010
>> /etc/apt/sources.list"
$ gpg -a --export 7638D0442B90D010 | sudo apt-key add -
sudo apt-get update


$ sudo apt-get install -t experimental qtbase5-dev qtbase5-private-dev libqt5x11extras5-dev qtscript5-dev qttools5-dev libqt5svg5-dev libqt5xmlpatterns5-dev qttools5-dev-tools qtdeclarative5-dev
# If you have key warnings, you can install them with
gpg --keyserver pgpkeys.mit.edu --recv-keys 8B48AD6246925553
gpg -a --export 8B48AD6246925553 | sudo apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-keys 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | sudo apt-key add -
</syntaxhighlight>
<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; word-wrap: normal;">
sudo apt-get install -t experimental qtbase5-dev qtbase5-private-dev libqt5x11extras5-dev qtscript5-dev qttools5-dev libqt5svg5-dev libqt5xmlpatterns5-dev qttools5-dev-tools qtdeclarative5-dev
</pre>
</pre>
== Download official QT build ==
From [https://www.qt.io/download qt download page], you can download the opensource qt installer that will be able to download and install locally different versions of qt, including the latest stable and development version.

Latest revision as of 17:49, 10 December 2023

Note

This page is archived. See page history.


Use Qt5 for Development

Qt is the base of mostly all KDE software. Thus, when developing any KDE application or framework, you require Qt. For this, either you can use development packages by your distribution or the Qt company or compile Qt yourself. Note that using Qt development packages often is the more convenient way. If the Qt version provided by your distribution is recent enough (in terms of version, features and bug fixes) and you do not have any specific reason to do otherwise, use Qt distribution packages.

If you still want to compile Qt from source, the recommended way to do it is using kdesrc-build. This also makes sure that you use the version of the Qt framework recommended by the KDE community, i.e. the KDE Qt patch collection.

The rest of this page is old content.

Build Qt5 from Sources

In the following, we explain how to build Qt5 from sources. Choose one of the following sections to get your Qt setup.

  1. Full Debug Build: If you build Qt with the intention to actually develop Qt patches then you should go for a full debug build.
    • Pro: full control and debugging capabilities
    • Contra: takes long to compile on the first time, might be an additional source of errors for beginners
  2. Release Build: If you merely need Qt to develop KDE applications then you should go for the release with debug symbol version.
    • Pro: This build is the most ideal build when developing applications and tuning performance. It has the speed of a release build but with debug symbols which give you more information in for example kcachegrind with data collected through valgrind.
    • Contra: The Qt libraries will be quite a lot bigger due to the debug symbols.

Note that it is not officially supported to build just individual frameworks (though it works). This might be caused by limited time or disk space and hence you just want to build some of Qt5. In this case, you could restrict yourself to separate checkouts of qtbase.git, qtsvg.git, qtx11extras.git, qtscript.git and qttools.git. This is enough to build frameworks/* (but not enough for e.g. plasma-framework).

Both instructions contain the following steps, only the configure-step differs.

Required Tools

You need the following tools:

  • Git
  • Perl
  • Python

Initial Clone of the Qt5 Repository

To clone the required sources to build all of Qt5 execute:

git clone git://code.qt.io/qt/qt5.git --branch 5.5

Configure and Build: Variant 1 (Full Debug Build)

cd qt5
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples \
  -dbus -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -developer-build
make

Configure and Build: Variant 2 (Release Build)

cd qt5
./init-repository
./configure -prefix $PWD/qtbase -opensource -confirm-license -nomake tests -nomake examples -dbus \
  -no-separate-debug-info -xcb -system-xcb -qpa xcb -no-gtkstyle -release -force-debug-info -reduce-relocations \
  -optimized-qmake
make

Later Update of the Qt5 Repository

To update qt5 later:

git pull
git submodule sync
git submodule update --recursive

If you saw changes (i.e. qt5.git got updated since last time),

./configure [...same as above...]
make
echo $?    # you should make extra sure that 'make' didn't abort with an error, especially when using -j

Distribution Specific Notes

Note

ArchLinux users: qtwebkit and qtwebengine use Python to generate some files, but they use Python 2.x syntax. So you have to make python pointing to /usr/bin/python2, to do that see the Arch Wiki.


Qt based libraries

You'll probably want to also compile your own Qt-based dependencies of KDE software, like poppler or libaccounts-qt to avoid mixing your Qt with the distro Qt. To do this, add this line to your kdesrc-buildrc

include extragear/utils/kdesrc-build/data/build-include/custom-qt5-libs.ksb

Use Qt5 Distribution Packages

  • Pro: faster to get started, one source of errors less
  • Contra: usually doesn't have debug symbols. Great for developing applications and measuring performance. Not so great for tuning performance (you'd need debug symbols for that).

Note that the Qt version currently must be >= 5.5

openSUSE 13.2 (outdated)

WARN: It is probably better not to use 13.2 anymore; go for 42.1 instead.

$ sudo zypper install libqt5-qttools libgypsy0 libqt5-creator libqt5-linguist libqt5-qtbase-common-devel libqt5-qtbase-debugsource libqt5-qtbase-devel libqt5-qtbase-doc libqt5-qtbase-examples libqt5-qtdeclarative-debugsource libqt5-qtdeclarative-devel libqt5-qtdeclarative-examples libqt5-qtdeclarative-tools libqt5-qtdoc libqt5-qtgraphicaleffects libqt5-qtimageformats libqt5-qtimageformats-debugsource libqt5-qtimageformats-devel libqt5-qtmultimedia-devel libqt5-qtmultimedia-examples libqt5-qtquick1-devel libqt5-qtquickcontrols libqt5-qtscript-devel libqt5-qtscript-examples libqt5-qtsvg-devel libqt5-qttools-debugsource libqt5-qttools-devel libqt5-qtx11extras-devel libqt5-qtxmlpatterns-devel libqt5-qtxmlpatterns-examples libQt5CLucene5 libQt5Concurrent-devel libQt5Concurrent5 libQt5Core-devel libQt5Core5 libQt5DBus-devel libQt5DBus5 libQt5Declarative5 libQt5Designer5 libQt5DesignerComponents5 libQt5Gui-devel libQt5Gui5 libQt5Help5 libQt5Multimedia5 libQt5Network-devel libQt5Network5 libQt5OpenGL-devel libQt5OpenGL5 libQt5Positioning5 libQt5PrintSupport-devel libQt5PrintSupport5 libQt5Script5 libQt5Sensors5 libQt5Sql-devel libQt5Sql5 libQt5Sql5-mysql libQt5Sql5-postgresql libQt5Sql5-sqlite libQt5Sql5-unixODBC libQt5Svg5 libQt5Test-devel libQt5Test5 libQt5WebKit5 libQt5WebKitWidgets5 libQt5Widgets-devel libQt5Widgets5 libQt5X11Extras5 libQt5Xml-devel libQt5Xml5 libQt5XmlPatterns5 libQtQuick5 libQt5WebKitWidgets-devel libqt5-qtbase-private-headers-devel

(these might be too much packages but with those the KF5 build worked)

Debian

New major releases (those with a .0 suffix) are usually skipped from Debian/testing, but often provided via experimental. To get packages from experimental you should know what you do (acting on your own risk ;) ) and add the following line to your /etc/apt/sources.list file.

sudo sh -c \
"echo 'deb http://ftp.debian.org/debian experimental main' \
>> /etc/apt/sources.list"
sudo apt-get update

# If you have key warnings, you can install them with
gpg --keyserver pgpkeys.mit.edu --recv-keys 8B48AD6246925553
gpg -a --export 8B48AD6246925553 | sudo apt-key add -
gpg --keyserver pgpkeys.mit.edu --recv-keys 7638D0442B90D010
gpg -a --export 7638D0442B90D010 | sudo apt-key add -
sudo apt-get install -t experimental qtbase5-dev qtbase5-private-dev libqt5x11extras5-dev qtscript5-dev qttools5-dev libqt5svg5-dev libqt5xmlpatterns5-dev qttools5-dev-tools qtdeclarative5-dev

Download official QT build

From qt download page, you can download the opensource qt installer that will be able to download and install locally different versions of qt, including the latest stable and development version.