1<section xmlns="http://docbook.org/ns/docbook"
2 xmlns:xlink="http://www.w3.org/1999/xlink"
3 xml:id="sec-language-qt">
4
5<title>Qt</title>
6
7<para>
8Qt is a comprehensive desktop and mobile application development toolkit for C++.
9Legacy support is available for Qt 3 and Qt 4, but all current development uses Qt 5.
10The Qt 5 packages in Nixpkgs are updated frequently to take advantage of new features,
11but older versions are typically retained until their support window ends.
12The most important consideration in packaging Qt-based software is ensuring that each package and all its dependencies use the same version of Qt 5;
13this consideration motivates most of the tools described below.
14</para>
15
16<section xml:id="ssec-qt-libraries"><title>Packaging Libraries for Nixpkgs</title>
17
18<para>
19Whenever possible, libraries that use Qt 5 should be built with each available version.
20Packages providing libraries should be added to the top-level function <varname>mkLibsForQt5</varname>,
21which is used to build a set of libraries for every Qt 5 version.
22A special <varname>callPackage</varname> function is used in this scope to ensure that the entire dependency tree uses the same Qt 5 version.
23Import dependencies unqualified, i.e., <literal>qtbase</literal> not <literal>qt5.qtbase</literal>.
24<emphasis>Do not</emphasis> import a package set such as <literal>qt5</literal> or <literal>libsForQt5</literal>.
25</para>
26
27<para>
28If a library does not support a particular version of Qt 5, it is best to mark it as broken by setting its <literal>meta.broken</literal> attribute.
29A package may be marked broken for certain versions by testing the <literal>qtbase.version</literal> attribute, which will always give the current Qt 5 version.
30</para>
31
32</section>
33
34<section xml:id="ssec-qt-applications"><title>Packaging Applications for Nixpkgs</title>
35
36<para>
37Call your application expression using <literal>libsForQt5.callPackage</literal> instead of <literal>callPackage</literal>.
38Import dependencies unqualified, i.e., <literal>qtbase</literal> not <literal>qt5.qtbase</literal>.
39<emphasis>Do not</emphasis> import a package set such as <literal>qt5</literal> or <literal>libsForQt5</literal>.
40</para>
41
42<para>
43Qt 5 maintains strict backward compatibility, so it is generally best to build an application package against the latest version using the <varname>libsForQt5</varname> library set.
44In case a package does not build with the latest Qt version, it is possible to pick a set pinned to a particular version, e.g. <varname>libsForQt55</varname> for Qt 5.5, if that is the latest version the package supports.
45If a package must be pinned to an older Qt version, be sure to file a bug upstream;
46because Qt is strictly backwards-compatible, any incompatibility is by definition a bug in the application.
47</para>
48
49<para>
50When testing applications in Nixpkgs, it is a common practice to build the package with <literal>nix-build</literal> and run it using the created symbolic link.
51This will not work with Qt applications, however, because they have many hard runtime requirements that can only be guaranteed if the package is actually installed.
52To test a Qt application, install it with <literal>nix-env</literal> or run it inside <literal>nix-shell</literal>.
53</para>
54
55</section>
56
57</section>
58