[Interest] Replacement for Qt Script

Jason H jhihn at gmx.com
Mon Apr 18 17:06:59 CEST 2016


ttps://forum.qt.io/topic/52306/qt-5-5-qt-script-deprecated-what-is-replacement/12
> 
> I saw this thread, but it did not seem to offer a clear detail other than to use QJSEngine and QJSValue directly.  Specifically I use qScriptRegisterMetaType very heavy to add custom types.  I know if I am using QML I can use qmlRegisterType<T>(uri, 1, 0, "T") but it only makes the type available via the declarative components.  It also requires the object be a QObject which means sharing pointers.  There is also a problem inside of the Javascript.  It is very cumbersome to dynamically create these types.  I understand I am fighting QML, but my design is not as declarative as it is creating objects that can be passed back into C++.   I may be missing something though.
> 
> As an example below with a type called MyStruct:
> 
> ... Qt Script...
> 
> var myStruct = new MyStruct();
> myStruct.x = 10;
> 
>  ....QML...
> 
> var myStruct;
> var component = Qt.createComponent(???);
>  if (component.status == Component.Ready) {
>         myStruct = component.createObject(parent, {"x": 100, "y": 100});
> }
>   
> What would ??? be?

If MyStruct is just a JS object, then just use JS. function MyStruct(){ return {"x": 100, "y": 100}; }; var myStruct = new MyStruct();
You only need createObject when you are creating an object defined in C++ or dynamic object from QML.




More information about the Interest mailing list