-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
None
-
6.8
-
None
-
Can be reproduced under at least Linux (tested under Arch Linux, Gentoo) and Windows (test under MSYS2 UCRT64 environment), with the most recent version of Qt from the distro's package repo.
-
-
b99d03a72 (dev), 33020c88f (6.9), 76bfb786b (6.8)
This code:
cmake_minimum_required(VERSION 3.28)
cmake_policy(VERSION 3.28)
project(X)
set(QT_DEFAULT_MAJOR_VERSION 6)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui Widgets LinguistTools)
message(STATUS "QT Major Version: " ${QT_VERSION_MAJOR})
is supposed to select QT6 in the mixed Qt5/Qt6 environment, but it selects Qt5.
– QT Major Version: 5
The usage is suggested by the Qt official documentation:
https://doc.qt.io/qt-6/cmake-qt5-and-qt6-compatibility.html#supporting-older-qt-5-versions
Here we let find_package(<PackageName>...) try to find first Qt 6, and if that fails Qt 5, under the name QT. If either of them is found, find_package will succeed, and the CMake variable QT_VERSION_MAJOR will be defined to either 5 or 6.
To reproduce the issue, ensure you have both Qt 5 and Qt 6 development package installed on your distro.
The actual behavior is:
1. it does NOT try to find first Qt 6 and if that fails Qt 5 as described in the documentation.
2. weither QT_DEFAULT_MAJOR_VERSION is set, it will still always find and use Qt 5 instead of Qt 6
See also:
For Gerrit Dashboard: QTBUG-133574 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
623516,10 | Fix documentation for multi-version support | dev | qt/qtdoc | Status: MERGED | +2 | 0 |
632559,2 | Fix documentation for multi-version support | 6.9 | qt/qtdoc | Status: MERGED | +2 | 0 |
632709,3 | Fix documentation for multi-version support | 6.8 | qt/qtdoc | Status: MERGED | +2 | 0 |