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. Is it possible to build QT 6.2.2 with C++20?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to build QT 6.2.2 with C++20?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 6.1k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    Dmitriano
    wrote on last edited by Dmitriano
    #1

    What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

    Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

    By default QT is built with C++17:

    Using C++ standard ..................... C++17

    jsulmJ J.HilkJ D 3 Replies Last reply
    0
    • D Dmitriano

      What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

      Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

      By default QT is built with C++17:

      Using C++ standard ..................... C++17

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

      What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

      Nothing.
      You can use newer C++ standards in your Qt app with Qt which was used with an older C++ standard.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 1 Reply Last reply
      2
      • D Dmitriano

        What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

        Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

        By default QT is built with C++17:

        Using C++ standard ..................... C++17

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

        What happens if my app is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

        nothing out of the ordinary, should work just fine.

        Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

        IIRC you simply pass -std=c++20 to the make call ?
        maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :D


        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.

        JohanSoloJ D 2 Replies Last reply
        2
        • jsulmJ jsulm

          @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

          What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

          Nothing.
          You can use newer C++ standards in your Qt app with Qt which was used with an older C++ standard.

          D Offline
          D Offline
          Dmitriano
          wrote on last edited by
          #4

          @jsulm what about calling std::string QString::toStdString() const in my app? Is it header only?

          jsulmJ 1 Reply Last reply
          0
          • D Dmitriano

            @jsulm what about calling std::string QString::toStdString() const in my app? Is it header only?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

            Is it header only?

            No, it's not.
            Is there a reason why you are asking this?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply
            0
            • jsulmJ jsulm

              @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

              Is it header only?

              No, it's not.
              Is there a reason why you are asking this?

              D Offline
              D Offline
              Dmitriano
              wrote on last edited by Dmitriano
              #6

              @jsulm I afraid that std::string in my app can differ from std::string in QT. At least I am not absolutely sure that it is not.

              jsulmJ 1 Reply Last reply
              0
              • D Dmitriano

                @jsulm I afraid that std::string in my app can differ from std::string in QT. At least I am not absolutely sure that it is not.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                std::string in QT

                There is no std::string in Qt.
                std::string (as anything else from std namespace) comes from C++ standard library.
                Which C++ standard library you're using depends on the compiler, not Qt.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                  std::string in QT

                  There is no std::string in Qt.
                  std::string (as anything else from std namespace) comes from C++ standard library.
                  Which C++ standard library you're using depends on the compiler, not Qt.

                  D Offline
                  D Offline
                  Dmitriano
                  wrote on last edited by Dmitriano
                  #8

                  @jsulm are you sure? see https://stackoverflow.com/questions/70241529/c17-and-c20-library-compatibility/70241655, for example, most people say that it is different std::strings

                  jsulmJ 1 Reply Last reply
                  0
                  • D Dmitriano

                    @jsulm are you sure? see https://stackoverflow.com/questions/70241529/c17-and-c20-library-compatibility/70241655, for example, most people say that it is different std::strings

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                    are you sure?

                    Yes, I am. Qt does not implement std::string. Or can you point me to its implementation sources in Qt?
                    "most people say that it is different" - I fail to see that "most" people say that. Most actually tell you same as what I do.
                    From my own experience I can tell that there is no problem using a newer C++ standatd in a Qt application than the one used to build Qt.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    D 1 Reply Last reply
                    0
                    • J.HilkJ J.Hilk

                      @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                      What happens if my app is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

                      nothing out of the ordinary, should work just fine.

                      Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

                      IIRC you simply pass -std=c++20 to the make call ?
                      maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :D

                      JohanSoloJ Offline
                      JohanSoloJ Offline
                      JohanSolo
                      wrote on last edited by
                      #10

                      @J-Hilk said in Is it possible to build QT 6.2.2 with C++20?:

                      IIRC you simply pass -std=c++20 to the make call ?
                      maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :D

                      This can indeed be done: set_property(TARGET tgt PROPERTY CXX_STANDARD 20), according to the cmake documentation. This works for individual targets. You can set it "project-wide" by using set (CMAKE_CXX_STANDARD 20).

                      `They did not know it was impossible, so they did it.'
                      -- Mark Twain

                      1 Reply Last reply
                      1
                      • jsulmJ jsulm

                        @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                        are you sure?

                        Yes, I am. Qt does not implement std::string. Or can you point me to its implementation sources in Qt?
                        "most people say that it is different" - I fail to see that "most" people say that. Most actually tell you same as what I do.
                        From my own experience I can tell that there is no problem using a newer C++ standatd in a Qt application than the one used to build Qt.

                        D Offline
                        D Offline
                        Dmitriano
                        wrote on last edited by Dmitriano
                        #11

                        @jsulm It is irrelevant where are the sources, it is about ABI compatibility between C++17 and C++20 runtime libs, but you are right about what people say, I misunderstood some answers on stackoverflow.com.

                        1 Reply Last reply
                        0
                        • J.HilkJ J.Hilk

                          @Dmitriano said in Is it possible to build QT 6.2.2 with C++20?:

                          What happens if my app is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

                          nothing out of the ordinary, should work just fine.

                          Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

                          IIRC you simply pass -std=c++20 to the make call ?
                          maybe there's an option in the cmake file to force this too, but I do not know enough about cmake to help here :D

                          D Offline
                          D Offline
                          Dmitriano
                          wrote on last edited by Dmitriano
                          #12

                          @J-Hilk Need to pass -std=c++20 to configure.bat call, not to 'make' call.

                          J.HilkJ 1 Reply Last reply
                          0
                          • D Dmitriano

                            @J-Hilk Need to pass -std=c++20 to configure.bat call, not to 'make' call.

                            J.HilkJ Offline
                            J.HilkJ Offline
                            J.Hilk
                            Moderators
                            wrote on last edited by
                            #13

                            @Dmitriano
                            alt text

                            right, I need more coffee


                            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.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SimonSchroeder
                              wrote on last edited by
                              #14

                              With MSVC not all versions work together. You cannot (always) link VS2013 code with VS2019 code, though you can link VS2017 and VS2019 code. The selected version of the standard normally does not impact compatibility.

                              Unfortunately, this is actually a reasonable question to ask: GCC once broke ABI compatibility for std::string when introducing C++11. There is a define in that case to compile C++11 against the old ABI. I don't know of any case with MSVC where this was a problem.

                              Also, this question is quite relevant IMHO in the context of Qt. When we ported our software from wxWidgets to Qt we had a lot of trouble with QString::toStdString() with MSVC. Something wasn't linked properly such that our software always crashed when std::string's destructor was called. We haven't figured it out, but switched over to using QString::toUtf8().data() instead, which honestly is a better solution as this way the encoding is known.

                              @Dmitriano that is indeed a good and valid question. But, you don't have to fear anything mixing C++17 and C++20 code with MSVC.

                              1 Reply Last reply
                              3
                              • D Dmitriano

                                What happens if my app that is built with C++20 (/std:c++20 option) uses QT built with C++17 (/std:c++17 option)?

                                Is there a way (a configuration option) to build QT with /std:c++20 with MSVC2019 and CLang 12?

                                By default QT is built with C++17:

                                Using C++ standard ..................... C++17

                                D Offline
                                D Offline
                                Dmitriano
                                wrote on last edited by
                                #15

                                @Dmitriano There is -c++std c++20 configuration parameter, but it is not clear does it work correctly with android builds, because there is still

                                    -DCMAKE_CXX_STANDARD=17
                                

                                in configuration log.

                                D 1 Reply Last reply
                                0
                                • D Dmitriano

                                  @Dmitriano There is -c++std c++20 configuration parameter, but it is not clear does it work correctly with android builds, because there is still

                                      -DCMAKE_CXX_STANDARD=17
                                  

                                  in configuration log.

                                  D Offline
                                  D Offline
                                  Dmitriano
                                  wrote on last edited by
                                  #16

                                  @Dmitriano I am not sure what does it exactly mean but Regarding CMAKE_CXX_STANDARD=17, that's only used for the architecture extraction compile project, see https://bugreports.qt.io/browse/QTBUG-99108

                                  1 Reply Last reply
                                  0

                                  • Login

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