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
To fix it:
as the Qt on mac is built by clang, in "Qt Creator" -> "Preferences" -> "Kits", you should set "Compiler" to clang.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With