shengfu zou
shengfu zou

Reputation: 600

No type named 'u16string' in namespace 'std'

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 

Upvotes: 6

Views: 4962

Answers (3)

xwl
xwl

Reputation: 860

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

Upvotes: 7

shengfu zou
shengfu zou

Reputation: 600

The problem is in the file ExpGame.pro.I delete code as bellow:

QMAKE_CXXFLAGS += -std=c++11

And it is OK.

Upvotes: -1

legends2k
legends2k

Reputation: 32964

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

Earlier you would have included some library's header which in turn included <string>; this, after some update perhaps, would've stopped including it directly and thus the error.

How to fix it?

Include the proper header in your source to avoid these kind of issues.

#include <string>

in the translation unit where the error occurs and make sure you're referring to it with the namespace: std::u16string.

Upvotes: 0

Related Questions