Is it possible to build QT 6.2.2 with C++20?
-
@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. -
@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. -
@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 :DThis 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 usingset (CMAKE_CXX_STANDARD 20)
. -
right, I need more coffee
-
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.
-
@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