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

Thorbjørn Lindeijer bjorn at lindeijer.nl
Mon Jun 20 17:02:32 CEST 2022


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


More information about the Interest mailing list