10

After upgrading to Qt 6.0, the compiler told me

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')

According to Qt's documentation, it can be imported by adding QT += core5compat. However, the compiler told me that "Unknown module(s) in QT: core5compat".

How to solve this problem?

1

3 Answers 3

14
  1. Make sure that you have installed "Qt 5 Compatibility Module".
  2. Add QT += core5compat in .pro file.
  3. Replace #include <QtCore/QTextCodec> to #include <QTextCodec>

Qt Installer

2
  • 3
    As the QTextCodec now lives in the compatibility library, is there a replacement class?
    – albert
    Commented Jan 28, 2022 at 13:21
  • 1
    @albert QStringConverter is QTextCodec's replacement class. Commented Jun 9, 2022 at 17:41
7

The QTextCodec class was moved to the core5compat submodule so it is not enough to add that in the .pro, but you must correct the import to:

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

Or simply

#include <QTextCodec>

On the other hand, you must install this module since it does not come by default and for this you must use Maintenance Tool.

2
  • 2
    As the QTextCodec now lives in the compatibility library, is there a replacement class?
    – albert
    Commented Jan 28, 2022 at 13:21
  • 2
    @albert QStringConverter is QTextCodec's replacement class. Commented Jun 9, 2022 at 17:40
2

add greaterThan(QT_MAJOR_VERSION,5): QT += core5compat in .pro file

1
  • 1
    Please be more elaborate, provide a comprehensive answer.
    – rawrex
    Commented Jun 27, 2021 at 3:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.