14

I have both qt4 and qt5 on my Linux system. qt4 is used by default. What is a clean way to change that so that qmake uses qmake-qt5 by default?

4
  • Please provide output of ls -l $(which qmake) Commented Sep 28, 2016 at 0:20
  • lrwxrwxrwx 1 root root 23 Sep 3 14:14 /usr/bin/qmake -> /usr/lib64/qt/bin/qmake*
    – niko
    Commented Sep 28, 2016 at 0:22
  • Isn't there something more elegant than messing with symlinks?
    – niko
    Commented Sep 28, 2016 at 0:23
  • 1
    I dont know of any better and elegant way than that Commented Sep 28, 2016 at 3:06

3 Answers 3

17

The system might have different meta packages that handle the default. For example on Debian there is a qt4-default and a qt5-default package, installing one of them will uninstall the other and set the symlinks appropriately

14

Step 0: Install qtchooser in your system.

$sudo apt-get install qtchooser

Step 1: locate your qtchooser configure file in your system.

$ locate qtchooser | grep conf

/usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
/usr/lib/x86_64-linux-gnu/qtchooser/4.conf
/usr/lib/x86_64-linux-gnu/qtchooser/5.conf
/usr/lib/x86_64-linux-gnu/qtchooser/qt4.conf
/usr/lib/x86_64-linux-gnu/qtchooser/qt5.conf

The command result may be different from yours. Those x.conf files represent all of qt versions qtchooser could recognized in your system. Each x.conf file is a symbolic link to a file configured the qt you have installed. Modifying the default.conf could configure the default qt version you expected.

Step 2: Find out the file location the symbolic link file default.conf linked to.

$ls -l /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf
lrwxrwxrwx 1 root root 53 x xx xxx /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf -> ../../../../share/qtchooser/qt4-x86_64-lnux-gnu.conf

Step 3: Create your qt version conf file

The result of step 2 shows the location of all qt version conf file: /usr/share/qtchooser. You just create a conf file specified your qt version in this path. For example, my qt is installed at /opt/Qt5.13.1/ and I want to set this qt version as the default one in my system. We could create a file named like qt5.13.1.conf.

$cd /usr/share/qtchooser
$sudo vi qt5.13.1.conf

and fill in the following two lines: first line means the qmake location and another represents the library path.

/opt/Qt5.13.1/5.13.1/gcc_64/bin
/opt/Qt5.13.1/5.13.1/gcc_64/lib

Step 4: Set your qt as the default one.

Just modify the default.conf symbolic link to your qt conf file created at step 3.

$cd /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/
$sudo ln -snf ../../../../share/qtchooser/qt5.13.1.conf default.conf

After complete those steps, the default qt has been configured and you can type following command to test and it should be your qt as the default.

$qmake -v
1
  • I did exactly what you said but i still get 5.12.8 from qmake -v instead of 6.6.1 which I installed in opt. Any idea?
    – Sigur
    Commented Jan 18 at 16:31
12

There is a tool named qtchooser to switch between Qt versions. On Debian and Ubuntu you can install it with apt-get install qtchooser.

Easiest way is to use it to list the alternatives and then create QT_SELECT environment variable.

$ qtchooser -list-versions
4
5
default
opt-qt55
qt4-i386-linux-gnu
qt4
qt5-i386-linux-gnu
qt5

Then you create QT_SELECT environment variable and set e.g. export QT_SELECT=4 or export QT_SELECT=5.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.