No name named 'u16string' in namespace 'std'

I am using QT 5.5.0.

When I compile the program, it shows “no type named“ u16string ”in the“ std ”namespace. The interesting part is that I successfully compiled it in the past, why doesn't it work now? It seems to be a problem with qstring.h .

How to fix it? Error occurs here

 #ifndef QSTRING_H #define QSTRING_H #if defined(QT_NO_CAST_FROM_ASCII) && defined(QT_RESTRICTED_CAST_FROM_ASCII) #error QT_NO_CAST_FROM_ASCII and QT_RESTRICTED_CAST_FROM_ASCII must not be defined at the same time #endif #include <QtCore/qchar.h> #include <QtCore/qbytearray.h> #include <QtCore/qrefcount.h> #include <QtCore/qnamespace.h> #include <string> #if defined(Q_OS_ANDROID) // std::wstring is disabled on android glibc, as bionic lacks certain features // that libstdc++ checks for (like mbcslen). namespace std { typedef basic_string<wchar_t> wstring; } #endif #if defined(Q_COMPILER_UNICODE_STRINGS) || defined(Q_QDOC) static inline QString fromStdU16String(const std::u16string &s); inline std::u16string toStdU16String() const; static inline QString fromStdU32String(const std::u32string &s); inline std::u32string toStdU32String() const; #endif 
+5
source share
3 answers

To fix this:

  • since Qt on mac is created by clang, in "Qt Creator" → "Preferences" → "Kits", you must install the compiler for clang.

  • instead of writing "QMAKE_CXXFLAGS + = -std = C ++ 11", add the below config to your .pro file:

     CONFIG += c++11 

https://forum.qt.io/topic/56064/solved-problem-with-qt-5-5/11

+7
source

The interesting part is that I have successfully compiled it in the past, why is it not working now?

Previously, you would include some library header, which in turn included <string> ; this, after some updating, might stop turning it on directly and therefore an error.

How to fix it?

Include the correct title in your source to avoid such problems.

 #include <string> 

in the translation block where the error occurred, and make sure you refer to it with the namespace: std::u16string .

0
source

The problem in the ExpGame.pro.I file removes the code below:

QMAKE_CXXFLAGS + = -std = C ++ 11

And all is well.

-1
source

All Articles