我正在使用QT 5.5.0.
当我编译一个程序时,它显示"命名空间'std'中没有名为'u16string'的类型".有趣的是,我过去成功地编译了它,为什么它现在失败了?这似乎很麻烦qstring.h.
我如何解决它?这是错误发生的地方
#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
Run Code Online (Sandbox Code Playgroud)
要解决这个问题:
由于Qt on mac是由clang构建的,在"Qt Creator" - >"Preferences" - >"Kits"中,你应该将"Compiler"设置为clang.
而不是写"QMAKE_CXXFLAGS + = -std = c ++ 11",将以下配置添加到您的.pro文件:
CONFIG += c++11
Run Code Online (Sandbox Code Playgroud)https://forum.qt.io/topic/56064/solved-problem-with-qt-5-5/11
有趣的是我过去编译成功了,为什么现在编译失败了?
早些时候,您可能已经包含了一些库的标头,而这些标头又包含<string>;也许在进行一些更新之后,这将停止直接包含它,从而停止错误。
如何修复它?
在源代码中包含正确的标头以避免此类问题。
#include <string>
Run Code Online (Sandbox Code Playgroud)
在发生错误的翻译单元中,并确保您使用名称空间引用它:std::u16string。
| 归档时间: |
|
| 查看次数: |
3804 次 |
| 最近记录: |