升级到Qt 6.0后,编译器告诉我
qzxing/src/QZXing.cpp:16: error: 'QtCore/QTextCodec' file not found
qzxing/src/QZXing.cpp:16:10: fatal error: 'QtCore/QTextCodec' file not found
#include <QtCore/QTextCodec>
^~~~~~~~~~~~~~~~~~~
qzxing/src/QZXing.cpp:16:10: note: did not find header 'QTextCodec' in framework 'QtCore' (loaded from '/Applications/Qt/6.0.0/clang_64/lib')
Run Code Online (Sandbox Code Playgroud)
根据Qt的文档,可以通过添加QT += core5compat. 然而,编译器告诉我“QT 中的未知模块:core5compat”。
如何解决这个问题呢?
Hao*_*Xie 13
QT += core5compat到.pro 文件中。#include <QtCore/QTextCodec>为#include <QTextCodec>QTextCodec 类已移至 core5compat 子模块,因此将其添加到 .pro 中还不够,但您必须将导入更正为:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QtCore/QTextCodec>
#else
#include <QtCore5Compat/QTextCodec>
#endif
Run Code Online (Sandbox Code Playgroud)
或者简单地
#include <QTextCodec>
Run Code Online (Sandbox Code Playgroud)
另一方面,您必须安装此模块,因为它不是默认提供的,为此您必须使用维护工具。