在 Qt 6 中找不到 QtCore/QTextCodec

问题描述

升级到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')

根据Qt's documentation,可以通过添加QT += core5compat来导入。 但是,编译器告诉我“QT 中的未知模块:core5compat”。

如何解决这个问题?

解决方法

  1. 确保您已安装“Qt 5 兼容模块”。
  2. 在 .pro 文件中添加 QT += core5compat
  3. #include <QtCore/QTextCodec> 替换为 #include <QTextCodec>

Qt Installer

,

QTextCodec 类已移至 core5compat 子模块,因此将其添加到 .pro 中是不够的,但您必须将导入更正为:

#if QT_VERSION < QT_VERSION_CHECK(6,0)
    #include <QtCore/QTextCodec>
#else
    #include <QtCore5Compat/QTextCodec>
#endif

或者干脆

#include <QTextCodec>

另一方面,你必须安装这个模块,因为它不是默认的,为此你必须使用维护工具

,

在 .pro 文件中添加 request.body.TGVAL

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...