Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No type named 'u16string' in namespace 'std'

Tags:

c++

qt

I'm using QT 5.5.0.

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

How do I fix it? Here is where the error happen

#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's 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 
like image 890
shengfu zou Avatar asked Jul 17 '15 08:07

shengfu zou


1 Answers

To fix it:

  1. as the Qt on mac is built by clang, in "Qt Creator" -> "Preferences" -> "Kits", you should set "Compiler" to clang.

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

    CONFIG += c++11
    

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

like image 126
xwl Avatar answered Nov 15 '22 09:11

xwl