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?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved Qt 6
24 Posts 5 Posters 5.3k Views 1 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.
  • S Offline
    S Offline
    SimonSchroeder
    wrote on 24 Sept 2021, 06:22 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
    • J JonB
      24 Sept 2021, 05:35

      @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 25 Sept 2021, 16:31 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 16 Dec 2023, 16:18 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.

        C 1 Reply Last reply 16 Dec 2023, 17:22
        0
        • X Xinlong
          16 Dec 2023, 16:18

          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.

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 16 Dec 2023, 17:22 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