[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


Hi,

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,
Andrei
________________________________
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)
Asynchronous,Synchronous,color0,color1,black,white,darkGray,gray,lightGray,red,green,blue,cyan,magenta,yellow,darkRed,darkGreen,darkBlue,etc.

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)
objectName,application,platform,inputMethod,styleHints,callLater,uiLanguage,objectNameChanged,include,isQtObject,color,rgba,hsla,hsva,colorEqual,rect,point,size,vector2d,vector3d,vector4d,quaternion,matrix4x4,lighter,darker,alpha,tint,formatDate,formatTime,formatDateTime,locale,url,resolvedUrl,openUrlExternally,font,fontFamilies,md5,btoa,atob,quit,exit,createQmlObject,createComponent,binding

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

module.js:

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

test.qml:

    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.

Thanks,
Thorbjørn
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- 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