UOS System Qt Version Switch

Content

Recently compiled Union Code software on UOS 1070 version, and the following error occurred:

-- process ts file: /home/alex/work/deepin-community/deepin-unioncode/assets/translations/en_US.ts CMake Error at assets/CMakeLists.txt:25 (message):   process ts file result : 1, with error: lupdate: could not exec   '/usr/lib/loongarch64-linux-gnu/qt4/bin/lupdate': No such file or directory

The prompt indicates that the lupdate command cannot be executed. However, the lupdate command does exist in the system; it just points to qtchooser.

alex@alex-loongson-MiniPC:~$ which lupdate /usr/bin/lupdate alex@alex-loongson-MiniPC:~$ ls -la /usr/bin/lupdate lrwxrwxrwx 1 root root 9 Apr 15 22:18 /usr/bin/lupdate -> qtchooser

So what is qtchooser? From the name, it is related to Qt version selection, and in fact, it is.

qtchooser is a tool for managing multiple Qt versions in the system, allowing users to select and switch between different Qt versions to meet the needs of development or runtime environments. With qtchooser, it is easy to switch between different versions of qmake or other Qt tools.

The role of qtchooser

  1. Manage multiple Qt versions: When multiple Qt versions are installed on the system, qtchooser provides a mechanism to select the required version.
  1. Path Configuration: Configure and switch the paths of different versions of qmake, uic, and other tools.
  1. Flexible Switching of Development Environments: For developers, it is possible to choose a specific Qt version based on different project requirements.

List the Qt versions in the system

Running the following command will list the configured Qt versions in the system:

alex@alex-loongson-MiniPC:~$ qtchooser -list-versions 4 5 default qt4-loongarch64-linux-gnu qt4 qt5-loongarch64-linux-gnu qt5

Among them:

  • 4 and 5 represent the configured Qt 4 and Qt 5.
  • default indicates the current default version of the system.
  • The rest are duplicates and can be ignored

Switch Qt Version

There are two ways to switch Qt versions: temporary switch and permanent switch.

1. Temporary Switch

You can specify the Qt version to use through the environment variable QT_SELECT:

`alex@alex-loongson-MiniPC:~$ QT_SELECT=5 qmake --version
QMake version 3.1
Using Qt version 5.11.3 in /usr/lib/loongarch64-linux-gnu

alex@alex-loongson-MiniPC:~$ QT_SELECT=4 qmake --version
qmake: could not exec'/usr/lib/loongarch64-linux-gnu/qt4/bin/qmake': No such file or directory
`

This will use the specified version in the current command without affecting other terminals or global settings.

From the command execution results, although the system is configured with versions 4 and 5, in fact, Qt 4 is not installed, so the execution will result in an error.

The compilation error at the beginning of the article is also because the system defaults to pointing the Qt version to 4, but version 4 is not installed, so executing lupdate will result in an error.

2. Permanent Switch

Change the default version to a certain version:

export QT_SELECT=5

Or add this line of code to the ~/.bashrc or ~/.zshrc file to keep the settings.

After adding the above environment variable settings to ~/.bashrc, open the terminal and execute qmake, and it will output normally:

alex@alex-loongson-MiniPC:~$ qmake --version QMake version 3.1 Using Qt version 5.11.3 in /usr/lib/loongarch64-linux-gnu

Use the qtchooser command to output the current Qt environment variables:

alex@alex-loongson-MiniPC:~$ qtchooser --print-env QT_SELECT="5" QTTOOLDIR="/usr/lib/qt5/bin" QTLIBDIR="/usr/lib/loongarch64-linux-gnu"

Configure new Qt version

If a new version of Qt is installed but not listed in qtchooser, it can be manually added through the configuration file:

1. Create a new configuration file:

sudo nano /usr/lib/loongarch64-linux-gnu/qtchooser/qt6.conf

Add two lines in the document:

/path/to/qt6/bin /path/to/qt6/lib

Replace /path/to/qt6 with the actual Qt installation path.

2. Test if the configuration is successful:

alex@alex-loongson-MiniPC:~$ qtchooser -list-versions 4 5 default qt4-loongarch64-linux-gnu qt4 qt5-loongarch64-linux-gnu qt5 qt6

Summary

qtchooser is a powerful tool that can effectively manage multiple Qt versions in the system. Through it, developers can quickly list, switch, or configure different Qt environments to meet the diverse needs of projects. Whether for temporary switching or permanent configuration, qtchooser provides a flexible way. At the same time, properly configuring the new version path can ensure the tool's scalability, bringing higher efficiency and convenience to development work.

Summary
The article discusses an error encountered while compiling Union Code software on UOS 1070, specifically related to the 'lupdate' command not executing due to a missing Qt version. The system has 'lupdate' linked to 'qtchooser', a tool for managing multiple Qt versions. 'qtchooser' allows users to select and switch between different Qt versions, facilitating development needs. The article explains how to list configured Qt versions using 'qtchooser -list-versions' and describes two methods for switching Qt versions: temporary and permanent. Temporary switching can be done using the 'QT_SELECT' environment variable, while permanent switching involves exporting the variable in shell configuration files. The article also covers how to configure new Qt versions in 'qtchooser' by creating a configuration file. Overall, 'qtchooser' is highlighted as a powerful tool for managing Qt environments, enabling developers to efficiently handle diverse project requirements by easily switching and configuring Qt versions.