[Interest] Qt 5 -> 6: In QQmlEngine, Qt.Checked, etc. are no longer available
Thorbjørn Lindeijer
bjorn at lindeijer.nl
Thu Jun 23 15:46:17 CEST 2022
On Thu, Jun 23, 2022, at 14:25, Andrei Golubev wrote:
> 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
This method was suggested on the Discord as well, but unfortunately it does not work. Trying to evaluate this script using QJSEngine::evaluate:
.import QtQml 2.15 as CoreQML
console.log(CoreQML.Qt.Checked)
yields:
At line 2: ReferenceError: CoreQML is not defined
Is that something I should report as a bug? I'd appreciate any other potential workarounds.
Thanks,
Thorbjørn
>
> --
> 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
More information about the Interest
mailing list