Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-133574

Setting QT_DEFAULT_MAJOR_VERSION to 6 doesn't select Qt6 over Qt5

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.8
    • Build System: CMake
    • 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.
    • All
    • 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

            lecris Cristian Le
            blumia Gary Wang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes