Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can I compile using C++ 20?
QtWS25 Last Chance

Can I compile using C++ 20?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 14.1k 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.
  • K Offline
    K Offline
    kitfox
    wrote on 24 Feb 2021, 22:27 last edited by
    #1

    I have an up-to-date installation of Qt. Is it possible to compile my code with the latest features in C++20? It seems C++17 is the latest Qt supports. I saw a post that suggested putting CONFIG += c++2a in my .pro file, but that doesn't seem to do anything for me.

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 24 Feb 2021, 22:43 last edited by
      #2

      Hi,

      Which version of Qt are you using ?
      With which compiler ?
      On which OS ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kitfox
        wrote on 25 Feb 2021, 00:11 last edited by
        #3

        Qt Version 5.15.0
        mingw-32 compiler
        Windows 10

        J 1 Reply Last reply 25 Feb 2021, 06:31
        0
        • B Offline
          B Offline
          Bonnie
          wrote on 25 Feb 2021, 02:36 last edited by Bonnie
          #4

          Qt will add -std=gnu++2a to CXXFLAGS after adding CONFIG+=c++2a in your case.
          But the final effect is depending on your compiler.

          1 Reply Last reply
          1
          • K kitfox
            25 Feb 2021, 00:11

            Qt Version 5.15.0
            mingw-32 compiler
            Windows 10

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 25 Feb 2021, 06:31 last edited by J.Hilk
            #5

            @kitfox well does your compiler support c++20 ?

            Where did you get it, and when (last update)

            if you make a simple c++ program with

            #include <iostream>
            
            using namespace std;
            
            int main()
            {
            #if __cplusplus >= 202002L
                // C++20 (and later) code
                cout << "C++20 (and later)" << endl;
            #endif
                return 0;
            }
            

            Does it then print something ?


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            K 1 Reply Last reply 25 Feb 2021, 14:43
            2
            • J J.Hilk
              25 Feb 2021, 06:31

              @kitfox well does your compiler support c++20 ?

              Where did you get it, and when (last update)

              if you make a simple c++ program with

              #include <iostream>
              
              using namespace std;
              
              int main()
              {
              #if __cplusplus >= 202002L
                  // C++20 (and later) code
                  cout << "C++20 (and later)" << endl;
              #endif
                  return 0;
              }
              

              Does it then print something ?

              K Offline
              K Offline
              kitfox
              wrote on 25 Feb 2021, 14:43 last edited by
              #6

              @J-Hilk
              I presume so since it is the mingw that comes with Qt 5.15.0. However, I do not know what the configuration options are that I need to get it to compile for C++20.

              When I compile with CONFIG += c++2a, __cplusplus gives the string 201709. CONFIG += c++17 gives 201703 and CONFIG += c++20 gives 201402. I'm not sure what to pass to indicate a different version of C++.

              If my compiler does not support c++ 20, how would I get one that does?

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 25 Feb 2021, 14:47 last edited by
                #7

                @kitfox said in Can I compile using C++ 20?:

                If my compiler does not support c++ 20, how would I get one that does?

                GCC 8 does not support more than 201709L I would guess according to the documentation. Therefore you need to upgrade it. MinGW64 does not provide a later compiler than gcc8: http://mingw-w64.org/doku.php/versions

                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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 25 Feb 2021, 15:05 last edited by
                  #8

                  AFAIK, on Windows, the best compiler on Windows with C++20 support is currently VS2019.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1

                  1/8

                  24 Feb 2021, 22:27

                  • Login

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