[Interest] Qt 5 -> 6: In QQmlEngine, Qt.Checked, etc. are no longer available

Thorbjørn Lindeijer bjorn at lindeijer.nl
Fri Jun 24 15:57:54 CEST 2022

On Fri, Jun 24, 2022, at 11:34, Ulf Hermann wrote:
> Indeed, in QQmlEngine the global object is frozen. You cannot replace
> its properties. Apparently you can still add to it, though. But see
> https://codereview.qt-project.org/c/qt/qtdeclarative/+/418536/1 for a
> possible solution.

Since you mentioned I can add members to the Qt object, my current workaround is as follows:

    QJSValue qtObject = globalObject.property(QStringLiteral("Qt"));
    auto &qtNamespace = Qt::staticMetaObject;
    for (int i = qtNamespace.enumeratorCount(); i >= 0; --i) {
        auto metaEnum = qtNamespace.enumerator(i);
        for (int k = metaEnum.keyCount(); k >= 0; --k)
            qtObject.setProperty(QString::fromLatin1(metaEnum.key(k)), metaEnum.value(k));

This works in QQmlEngine as well, so I think that'll be fine until these are added back properly. :-)


More information about the Interest mailing list