Qt Build Qt5 for Ubuntu 20.04 - lukechendev/purecoding GitHub Wiki

Why build Qt5 locally

The pre-built binaries are unstable The pre-built binaries aren't available at all for a specific Linux distro You need a specific version of Qt5 to develop against You need a feature that isn't built into the stock binaries (ex. support for a specific multimedia back-end) A debug version of Qt is needed

Procedure

Setup Linux

You'll need git and all the usual tools for building stuff in Linux.  For more details, see the full list of requirements on Qt's wiki.

Get Dependency Packages

In Ubuntu:

sudo apt-get build-dep qt5-default
sudo apt-get install libxcb-xinerama0-dev 

If you see an error about a "sources.list" file, go to Software and Updates > Ubuntu Software and select the "Source Code" option.

Clone Source

git clone https://code.qt.io/qt/qt5.git
cd qt5
git checkout origin/5.15.2

Init Source

Run this line to initialize the source repo.  The parts after '--module-subset' aren't really required, but it speeds up the build by excluding a bunch of modules Sync doesn't use.

perl init-repository --module-subset=default,-qtwebkit,-qtwebkit-examples,-qtwebengine,-qtsensors,-qtpurchasing,-qtcharts,-qtdatavis3d,-qtgamepad,-qtspeech,-qtlocation

Configure Build

Qt supports out-of-source shadow builds, so that's set up here.

cd ..
mkdir build
cd build
../qt5/configure -prefix /opt/Qt5.15.2 -opensource -confirm-license -optimized-qmake -developer-build -nomake examples -nomake tests

Configure options can change as needed.  This example sets up a debug developer build with no extra features in particular.  "Prefix" sets the install directory, /opt is a pretty normal default location, but it can be changed to anywhere that's convenient.

NOTE: Check the README about all the different configuration options in qt5/qtbase/config_help.txt.

NOTE FOR USING A COMMERCIAL LICENSE:

Before you start, download your Qt license file (qt-license.txt) from the Qt website and copy it into your Linux user's "$HOME" folder (the same place as .bashrc and stuff).  Then when you run the configure step, replace the -opensource flag with -commercial. Refer to Qt's documentation: https://doc.qt.io/qt-5/linux-building.html

After configure is done, it will print a configuration report to the console. The report is also available under (build dir)/config.summary.

If features are missing, check the configure log to figure out which dependency test failed.

Build

This will build and install to the path specified in 'prefix'.

make -j4
make install

Note: 'make install' won't add it to the system $PATH variable, or to Qt Creator.

You can test the build by navigating to (install dir)/bin and running './qmake -v'.  If it worked, then the output should match the build version:

:/opt/Qt5.15.2/bin$ ./qmake -v
QMake version 3.1
Using Qt version 5.15.2 in /opt/Qt5.15.2/lib

At this point, you can probably delete the temporary build folder.

Add to Qt Creator

For Qt Creator to use the new Qt version, it must be added as a 'kit' to Qt Creator.  Then, the kit must be enabled for the project you'd like to build.

To add a new kit inside Creator:

  1. Tools -> Options -> Kits -> Qt Versions -> Add Navigate to the location of the qmake executable (it's in the 'bin' directory of the build folder)

  2. Switch to the "Kits" tab Add a new one that uses the new version of Qt.

To use the new kit:

  1. Open the "Projects" tab on the left Under Build & Run, enable the new kit

  2. Switch to that kit under the project build settings in the bottom-left:

  3. Run a build with the new kit

External Links Qt Wiki:

https://wiki.qt.io/Building_Qt_5_from_Git

https://doc.qt.io/qt-5/linux-building.html