Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. CMake support for qt-version we are linking to

CMake support for qt-version we are linking to

Scheduled Pinned Locked Moved Solved Qt 6
9 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TomZ
    wrote on 29 Nov 2022, 21:30 last edited by
    #1

    The cmake variable QT_VERSION_MAJOR no longer has any value like it did in Qt5 (checked up to 641). Similar with the other 'version' variables. How do I get the Qt version in CMake?

    C 1 Reply Last reply 30 Nov 2022, 06:19
    0
    • T TomZ
      29 Nov 2022, 21:30

      The cmake variable QT_VERSION_MAJOR no longer has any value like it did in Qt5 (checked up to 641). Similar with the other 'version' variables. How do I get the Qt version in CMake?

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 Nov 2022, 06:19 last edited by
      #2

      @TomZ said in CMake support for qt-version we are linking to:

      no longer has any value like it did

      It has.

      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Sql)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Sql)
      message(STATUS "Qt version: ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
      
      -->
      -- Qt version: 6.5.0
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • T Offline
        T Offline
        TomZ
        wrote on 30 Nov 2022, 09:31 last edited by
        #3

        Oh, wow, calling find-package twice indeed manages to populate those variables. Weird, but I'm happy it does the trick!
        Thank you.

        C 1 Reply Last reply 30 Nov 2022, 10:09
        0
        • T TomZ
          30 Nov 2022, 09:31

          Oh, wow, calling find-package twice indeed manages to populate those variables. Weird, but I'm happy it does the trick!
          Thank you.

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 30 Nov 2022, 10:09 last edited by
          #4

          @TomZ said in CMake support for qt-version we are linking to:

          Weird, but I'm happy it does the trick!

          The first find_package() already sets it.

          find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Sql)
          message(STATUS "Qt version: ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
          find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Sql)
          message(STATUS "Qt version: ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
          
          -->
          -- Qt version: 6.5.0
          -- Qt version: 6.5.0
          

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • T Offline
            T Offline
            TomZ
            wrote on 30 Nov 2022, 10:42 last edited by
            #5

            Is there something special about the usage of NAMES with the call that fills those variables?

            My usage (since my code won't compile against Qt5) was simply;
            find_package(Qt6 COMPONENTS Core Quick Svg REQUIRED OPTIONAL_COMPONENTS Multimedia)

            Which did not set the version variables.

            So I needed to add the otherwise unneeded line find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) in order to get those variables.
            I don't understand the logic why my first line doesn't generate the version variables. Not sure if I care enough if you don't know, but if you know if this is a bug or if this is just me not knowing cmake well enough, I'd be happy to learn.

            Full cmake file here.

            1 Reply Last reply
            0
            • C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 30 Nov 2022, 10:46 last edited by
              #6

              Ok, I can see the problem. Imo they should also be set without the first call but they are not. Will take a look on it.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 30 Nov 2022, 10:57 last edited by
                #7

                I must say - those variables were also not set with Qt5. There I relied on e.g. 'Qt5Core_VERSION'

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xavierbaez
                  wrote on 21 Mar 2023, 05:02 last edited by
                  #8

                  Hello
                  I am trying desperately to get this working, it is not.
                  I am not sure what I am doing wrong.
                  Is there a special path or something?
                  For some reason, it is not detecting Qt6
                  I am using Manjaro

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    csab6597
                    wrote on 5 Apr 2025, 09:16 last edited by
                    #9

                    running into this issue years later...
                    for me the line find_package(Qt6 QUIET COMPONENTS Core Gui Widgets Multimedia MultimediaWidgets) will NOT populate the version numbers, only repeating with find_package(QT NAMES Qt6) will finally do.

                    1 Reply Last reply
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved