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. What changed with QString::toStdString() in QT6?

What changed with QString::toStdString() in QT6?

Scheduled Pinned Locked Moved Solved Qt 6
24 Posts 5 Posters 5.2k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #14

    The only difference is the const QString <-> QString now.
    Ste through your debugger with F11 to see that only those two functions are called.

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

    D 1 Reply Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      The only difference is the const QString <-> QString now.
      Ste through your debugger with F11 to see that only those two functions are called.

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

      @Christian-Ehrlicher Noticed that my original example works in Release configuration, but does not work in Debug. So probably the difference is that some copying or moving are optimized. Or probably something goes wrong if I link a debug version of the app with a release version of QT.

      Christian EhrlicherC 1 Reply Last reply
      0
      • D Dmitriano

        @Christian-Ehrlicher Noticed that my original example works in Release configuration, but does not work in Debug. So probably the difference is that some copying or moving are optimized. Or probably something goes wrong if I link a debug version of the app with a release version of QT.

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #16

        @Dmitriano said in What changed with QString::toStdString() in QT6?:

        if I link a debug version of the app with a release version of QT.

        You must not mix debug and release libraries on windows since they use a different MSVCRT

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

        JonBJ 1 Reply Last reply
        3
        • Christian EhrlicherC Christian Ehrlicher

          @Dmitriano said in What changed with QString::toStdString() in QT6?:

          if I link a debug version of the app with a release version of QT.

          You must not mix debug and release libraries on windows since they use a different MSVCRT

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #17

          @Christian-Ehrlicher said in What changed with QString::toStdString() in QT6?:

          You must not mix debug and release libraries on windows since they use a different MSVCRT

          I suggested a library mismatch might be at issue earlier, but seemed to be told this was causing "To avoid starting a battle"....

          I assume the OP means he has two quite separate builds of everything, with different, consistent compilation/linkage flags used throughout, and is not mixing anything debug with release at all.....

          1 Reply Last reply
          1
          • JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #18

            @Dmitriano
            When I said earlier about Googling qstring tostdstring crash and the stackoverflow post, there is https://stackoverflow.com/a/15611383/489865

            Your Qt DLLs need to be compiled with STL support and exactly the same C-Runtime Library as your code. It looks as though you are using two different CRTs at the same time, which would destroy the objects created on one heap by Qt into the heap used by your program.

            Check the DLL Usage with the Dependency Walker!

            That is what I had in mind, about the "same C-Runtime Library".

            Do you have the Windows Dependency Walker? It's a useful tool! If you run it on the misbehaving executable, check carefully for all the dependent libraries. If you see both debug and non-debug versions of things like MSVCRT involved, you have a problem! Everything, including your Qt libraries, must be compiled either for release or for debug, no mixture. Might that be the situation you are in?

            D 1 Reply Last reply
            1
            • JonBJ JonB

              @Dmitriano
              When I said earlier about Googling qstring tostdstring crash and the stackoverflow post, there is https://stackoverflow.com/a/15611383/489865

              Your Qt DLLs need to be compiled with STL support and exactly the same C-Runtime Library as your code. It looks as though you are using two different CRTs at the same time, which would destroy the objects created on one heap by Qt into the heap used by your program.

              Check the DLL Usage with the Dependency Walker!

              That is what I had in mind, about the "same C-Runtime Library".

              Do you have the Windows Dependency Walker? It's a useful tool! If you run it on the misbehaving executable, check carefully for all the dependent libraries. If you see both debug and non-debug versions of things like MSVCRT involved, you have a problem! Everything, including your Qt libraries, must be compiled either for release or for debug, no mixture. Might that be the situation you are in?

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

              @JonB said in What changed with QString::toStdString() in QT6?:

              Everything, including your Qt libraries, must be compiled either for release or for debug, no mixture. Might that be the situation you are in?

              Yes, it is exactly the situation I was in. And I was in the same situation with QT5, but it did not crash.

              JonBJ 1 Reply Last reply
              0
              • D Dmitriano

                @JonB said in What changed with QString::toStdString() in QT6?:

                Everything, including your Qt libraries, must be compiled either for release or for debug, no mixture. Might that be the situation you are in?

                Yes, it is exactly the situation I was in. And I was in the same situation with QT5, but it did not crash.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #20

                @Dmitriano said in What changed with QString::toStdString() in QT6?:

                And I was in the same situation with QT5, but it did not crash.

                Point taken, but that's a bit hit-or-miss. But since you have closed this thread I guess you are saying that sticking to release- or debug-only for everything has resolved your problem?

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

                  I had many problems with this myself when we started converting from wxWidgets to Qt. In that case it was some library mismatches. (In our case it was dynamic and static linking instead of release and debug.) Sometimes it has also to do with C++11 and C++98 being mixed.

                  However, our solution was to call str.toUtf8().data(). This has always worked. Also, it ensures that output, writing to text files, etc. is always UTF8 (which I believe it will not if using str.toStdString()). In addition on Windows (and only Windows!!) we call setlocale(LC_ALL, ".UTF8"); right at the beginning of main. This lets Windows know that all output on std::cout is actually UTF8.

                  1 Reply Last reply
                  1
                  • JonBJ JonB

                    @Dmitriano said in What changed with QString::toStdString() in QT6?:

                    And I was in the same situation with QT5, but it did not crash.

                    Point taken, but that's a bit hit-or-miss. But since you have closed this thread I guess you are saying that sticking to release- or debug-only for everything has resolved your problem?

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

                    @JonB said in What changed with QString::toStdString() in QT6?:

                    I guess you are saying that sticking to release- or debug-only for everything has resolved your problem?

                    Yes, I built release and debug versions of QT6.2RC1. If I build debug app with debug QT and release app with release QT it does not crash.

                    1 Reply Last reply
                    1
                    • X Offline
                      X Offline
                      Xinlong
                      wrote on last edited by
                      #23

                      I had a similar problem and it tuned out that I wrongly set the Runtime Library to be /MTd for the release mode, and it worked ok after I changed it back to /MD in Visual Stuidio 2019.

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • X Xinlong

                        I had a similar problem and it tuned out that I wrongly set the Runtime Library to be /MTd for the release mode, and it worked ok after I changed it back to /MD in Visual Stuidio 2019.

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #24

                        @Xinlong Yes, you can not mix different msvc runtimes in one executable.

                        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

                        • Login

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