Don't use qmlRegisterType with QT-5.14
AcceptedPublic

Authored by plevine on Sat, Nov 30, 5:37 AM.

Details

Reviewers
jriddell
davidedmundson
Group Reviewers
Plasma
Summary

Building Plymouth-kcm-5.17.3 against Qt 5.14.0_beta3 fails with:

../plymouth-kcm-5.17.3/src/kcm.cpp: In constructor 'KCMPlymouth::KCMPlymouth(QObject*, const QVariantList&)':
../plymouth-kcm-5.17.3/src/kcm.cpp:54:41: error: no matching function for call to 'qmlRegisterType<QStandardItemModel>()'
   54 |     qmlRegisterType<QStandardItemModel>();
      |                                         ^
In file included from /usr/include/qt5/QtQml/QtQml:9,
                 from /usr/include/KF5/KDeclarative/kquickaddons/configmodule.h:34,
                 from /usr/include/KF5/KDeclarative/KQuickAddons/ConfigModule:1,
                 from ../plymouth-kcm-5.17.3/src/kcm.h:28,
                 from ../plymouth-kcm-5.17.3/src/kcm.cpp:21:
/usr/include/qt5/QtQml/qqml.h:291:5: note: candidate: 'int qmlRegisterType(const char*, int, int, const char*) [with T = QStandardItemModel]'
  291 | int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
      |     ^~~~~~~~~~~~~~~
/usr/include/qt5/QtQml/qqml.h:291:5: note:   candidate expects 4 arguments, 0 provided
/usr/include/qt5/QtQml/qqml.h:322:5: note: candidate: 'template<class T, int metaObjectRevision> int qmlRegisterType(const char*, int, int, const char*)'
  322 | int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
      |     ^~~~~~~~~~~~~~~
/usr/include/qt5/QtQml/qqml.h:322:5: note:   template argument deduction/substitution failed:
../plymouth-kcm-5.17.3/src/kcm.cpp:54:41: note:   candidate expects 4 arguments, 0 provided
   54 |     qmlRegisterType<QStandardItemModel>();
      |                                         ^
../plymouth-kcm-5.17.3/src/kcm.cpp:55:34: error: no matching function for call to 'qmlRegisterType<KCMPlymouth>()'
   55 |     qmlRegisterType<KCMPlymouth>();
      |                                  ^
In file included from /usr/include/qt5/QtQml/QtQml:9,
                 from /usr/include/KF5/KDeclarative/kquickaddons/configmodule.h:34,
                 from /usr/include/KF5/KDeclarative/KQuickAddons/ConfigModule:1,
                 from ../plymouth-kcm-5.17.3/src/kcm.h:28,
                 from ../plymouth-kcm-5.17.3/src/kcm.cpp:21:
/usr/include/qt5/QtQml/qqml.h:291:5: note: candidate: 'int qmlRegisterType(const char*, int, int, const char*) [with T = KCMPlymouth]'
  291 | int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
      |     ^~~~~~~~~~~~~~~
/usr/include/qt5/QtQml/qqml.h:291:5: note:   candidate expects 4 arguments, 0 provided
/usr/include/qt5/QtQml/qqml.h:322:5: note: candidate: 'template<class T, int metaObjectRevision> int qmlRegisterType(const char*, int, int, const char*)'
  322 | int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
      |     ^~~~~~~~~~~~~~~
/usr/include/qt5/QtQml/qqml.h:322:5: note:   template argument deduction/substitution failed:
../plymouth-kcm-5.17.3/src/kcm.cpp:55:34: note:   candidate expects 4 arguments, 0 provided
   55 |     qmlRegisterType<KCMPlymouth>();
      |                                  ^
ninja: build stopped: subcommand failed.

From https://doc-snapshots.qt.io/qt5-5.14/qqmlengine-obsolete.html:

int qmlRegisterType()
This function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

This is an overloaded function.

Do not use this function. For anonymous type registrations, use qmlRegisterAnonymousType(), and make sure to provide a URI and a major version.

I don't have much experience with QT/KDE programming but these changes are sufficient to fix the build error on my end.

BUG: 414679

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
plevine created this revision.Sat, Nov 30, 5:37 AM
Restricted Application added a project: Plasma. · View Herald TranscriptSat, Nov 30, 5:37 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
plevine requested review of this revision.Sat, Nov 30, 5:37 AM
davidedmundson accepted this revision.Sat, Nov 30, 11:27 AM
davidedmundson added a subscriber: davidedmundson.

You'll find this with the other repos too.

In general I've been reverting the relevant path of the cmake that forces no deprecated.

This revision is now accepted and ready to land.Sat, Nov 30, 11:27 AM
zzag added a subscriber: zzag.Sat, Nov 30, 12:31 PM
zzag added inline comments.
src/kcm.cpp
55

You could use QT_VERSION_CHECK to make the code more readable, e.g.

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
    qmlRegisterType<QStandardItemModel>();
    qmlRegisterType<KCMPlymouth>();
#else
    qmlRegisterAnonymousType<QStandardItemModel>("KCMPlymouth", 1);
    qmlRegisterAnonymousType<KCMPlymouth>("KCMPlymouth", 1);
#endif
plevine updated this revision to Diff 70645.Sun, Dec 1, 12:00 AM

Use QT_VERSION_CHECK for clarity.