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

Andrei Golubev andrei.golubev at qt.io
Thu Jun 23 14:25:35 CEST 2022


AFAIK this was done on purpose [1]. You need to import the QtQml module inside your JS file e.g.

  .import QtQml 2.15 as CoreQML

Then accessing the Qt object via CoreQML.Qt should give you the enumerations.

[1]: https://codereview.qt-project.org/c/qt/qtdeclarative/+/319662 merged as cbe1869fbe7048f34513b201a1d9111a0a64257a

Best Regards,
From: Interest <interest-bounces at qt-project.org> on behalf of Thorbjørn Lindeijer <bjorn at lindeijer.nl>
Sent: Monday, June 20, 2022 5:02 PM
To: ;interest at qt-project.org;;; <interest at qt-project.org>
Subject: [Interest] Qt 5 -> 6: In QQmlEngine, Qt.Checked, etc. are no longer available

Dear list,

I'd like to upgrade the releases of my application from Qt 5.15 to Qt 6.2, but I'm met with a loss in functionality that I'm not sure how to resolve.

My application is scriptable using QQmlEngine, and with Qt 5, the loaded JS files had the global Qt namespace values available as part of the "Qt" variable:

> Object.keys(Qt)

The list goes on and on, so I've truncated it. But now with Qt 6, only a handful of members remain, basically none of the global namespace values are available anymore:

> Object.keys(Qt)

I did a quick test by loading a QML file, and in that file the value of Qt.Checked is available:


    const f = __filename
    const c = Qt.createComponent(`${FileInfo.path(f)}/test.qml`)
    let window = c.createObject()
    tiled.log(`from JS module: ${Qt.Checked}`)


    import QtQml
    QtObject {
        Component.onCompleted: {
            tiled.log(`from QML component: ${Qt.Checked}`)

The output:

    Importing module '/home/bjorn/.config/tiled/extensions/modules.mjs'
    from QML component: 2
    from JS module: undefined

Does anybody have any idea how I can make the Qt namespace values available in JS files when using Qt 6? This is critical since I depend on a number of these values in my scripting API.

Interest mailing list
Interest at qt-project.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220623/9a68112c/attachment.htm>

More information about the Interest mailing list