Building Qt 6 from source
If you want to build the framework and tools yourself or experiment with the latest unreleased code, then you can build Qt from the source code. If you're going to develop a specific Qt version from the source, then you can download the Qt 6 source code from the official releases link, as shown here: https://download.qt.io/official_releases/qt/6.0/.
If you are a commercial customer, then you can download the Source Packages from your Qt account portal. Platform-specific building instructions are discussed in the upcoming subsections.
You can also clone from the GitHub repository, and check out the desired branch. At the time of authoring this book, the Qt 6 branch remained inside the Qt 5 super module. You can clone the repository from the following link: git://code.qt.io/qt/qt5.git
.
The qt5.git
repository may get renamed to qt.git
in the future for maintainability. Please refer to the QTQAINFRA-4200
Qt ticket. Detailed instructions on how to build Qt from Git can be found at the following link: https://wiki.qt.io/Building_Qt_6_from_Git.
Ensure that you install the latest versions of Git, Perl, and Python on your machine. Make sure there is a working C++ compiler before proceeding to the platform-specific instructions in the next section.
Installing Qt on Windows from source
To install Qt 6 on Windows from source code, follow these next steps:
- First of all, download the source code from Git or from the open source download link mentioned earlier. You will get a compressed file as
qt-everywhere-src--%VERSION%.zip
, where%VERSION%
is the latest version (such asqt-everywhere-src-6.0.3.zip
). Please note that suffixes such as-everywhere-src-
may get removed in the future. - Once you have downloaded the source archive, extract it to a desired directory—for example,
C:\Qt6\src
. - In the next step, configure the build environment with a supported compiler and the required build tools.
- Then, add the respective installation directories of
CMake
,ninja
,Perl
, andPython
to yourPATH
environment variable. - The next step is to build the Qt library. To configure the Qt library for your machine type, run the
configure.bat
script in the source directory. - In this step, build Qt by typing the following command in Command Prompt:
>cmake --build . –parallel
- Next, enter the following command in Command Prompt to install Qt on your machine:
>cmake --install .
Your Windows machine is now ready to use Qt.
To understand more about the configure options, visit the following link:
https://doc.qt.io/qt-6/configure-options.html
Detailed build instructions can be found at the following link:
https://doc.qt.io/qt-6/windows-building.html
Installing Qt on Linux from source
To build the source package on Linux distributions, run the following set of instructions on your terminal:
- First of all, download the source code from Git or from the open source download link mentioned earlier. You will get a compressed file as
qt-everywhere-src--%VERSION%.tar.xz
, where%VERSION%
is the latest version (such asqt-everywhere-src-6.0.3.tar.xz
). Please note that suffixes such as-everywhere-src-
may get removed in the future. - Once you have downloaded the source archive, uncompress the archive and unpack it to a desired directory—for example,
/qt6
, as illustrated in the following code snippet:$ cd /qt6 $ tar xvf qt-everywhere-opensource-src-%VERSION%.tar.xz $ cd /qt6/qt-everywhere-opensource-src-%VERSION%
- To configure the Qt library for your machine, run the
./configure
script in the source directory, as illustrated in the following code snippet:$ ./configure
- To create the library and compile all the examples, tools, and tutorials, type the following commands:
$ cmake --build . --parallel $ cmake --install .
- The next step is to set the environment variables. In
.profile
(if your shell isbash
,ksh
,zsh
, orsh
), add the following lines of code:PATH=/usr/local/Qt-%VERSION%/bin:$PATH export PATH
In
.login
(if your shell iscsh
ortcsh
), add the following line of code:setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH
If you use a different shell, modify your environment variables accordingly. Qt is now ready to be used on your Linux machine.
Detailed building instructions for Linux/X11 can be found at the following link:
https://doc.qt.io/qt-6/linux-building.html
Installing Qt on macOS from source
Qt has a dependency on Xcode. To install Qt on your Mac, you will need Xcode installed on your machine. If you don't have Xcode installed on your machine, then you may proceed to install Xcode's Command Line Tools:
- To begin, type the following command on the terminal:
$ xcode-select --install   Â
- If the terminal shows the following output, then your system is ready for the next steps:
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
- To build the source package, run the following set of instructions on your terminal:
$ cd /qt6 $ tar xvf qt-everywhere-opensource-src-%VERSION%.tar          $ cd /qt6/qt-everywhere-opensource-src-%VERSION%
- To configure the Qt library for your Mac, run the
./configure
script in the source directory, as illustrated in the following code snippet:$ ./configure Â
- To create a library, run the
make
command, as follows:$ make
- If
-prefix
is outside the build directory, then type the following lines to install the library:$ sudo make -j1 install
- The next step is to set the environment variables. In
.profile
(if your shell isbash
), add the following lines of code:PATH=/usr/local/Qt-%VERSION%/bin:$PATH export PATH
In
.login
(if your shell iscsh
ortcsh
), add the following line of code:setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH
Your machine is now ready for Qt programming.
Detailed building instructions for macOS can be found here:
https://doc.qt.io/qt-6/macos-building.html
In this section, we learned how to install Qt from source on your favorite platform. Now, let's summarize our learning.