【问题标题】:QtCore/QTextCodec not found in Qt 6在 Qt 6 中找不到 QtCore/QTextCodec
【发布时间】:2021-03-30 10:51:55
【问题描述】:

升级到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”。

如何解决这个问题?

【问题讨论】:

  • 有同样的错误

标签: c++ qt qt6


【解决方案1】:

在 .pro 文件中添加greaterThan(QT_MAJOR_VERSION,5): QT += core5compat

【讨论】:

  • 请详细一点,提供全面的答案。
【解决方案2】:
  1. 确保您已安装“Qt 5 兼容模块”。
  2. 在 .pro 文件中添加QT += core5compat
  3. #include &lt;QtCore/QTextCodec&gt; 替换为#include &lt;QTextCodec&gt;

【讨论】:

    【解决方案3】:

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

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

    或者干脆

    #include <QTextCodec>
    

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

    【讨论】:

      猜你喜欢
      • 2012-11-12
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 1970-01-01
      • 2017-11-12
      • 2020-09-02
      相关资源
      最近更新 更多