What changed with QString::toStdString() in QT6?
-
wrote on 24 Sept 2021, 06:22 last edited by
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 usingstr.toStdString()
). In addition on Windows (and only Windows!!) we callsetlocale(LC_ALL, ".UTF8");
right at the beginning of main. This lets Windows know that all output onstd::cout
is actually UTF8. -
@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?
wrote on 25 Sept 2021, 16:31 last edited by@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.
-
wrote on 16 Dec 2023, 16:18 last edited by
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.
-
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.
@Xinlong Yes, you can not mix different msvc runtimes in one executable.