Details
-
Technical task
-
Resolution: Unresolved
-
P2: Important
-
ca27c051a (dev)
Description
Exhibit A: Where a JS object can be optimized away
Code
import QtQuick Window { width: 640 height: 480 visible: true title: foo() function foo(): string { let jsObj = {"key": "value"} return jsObj.key } }
Compiler output
Warning: main.qml:9:9: Could not compile function foo: Cannot generate efficient code for DefineObjectLiteral [compiler] let jsObj = {"key": "value"} ^^^
Exhibit B: Where a JS object is used to initialize a QML_STRUCTURED_VALUE
Code (adapted from https://github.com/qt/qtdeclarative/blob/v6.5.1/src/qml/doc/src/qmlfunctions.qdoc#L1451-L1489 )
// cpptypes.h class MyValueType { Q_GADGET QML_VALUE_TYPE(myValueType) QML_STRUCTURED_VALUE Q_PROPERTY(double d MEMBER d) Q_PROPERTY(QString e MEMBER e) double d; QString e; };
// Main.qml import QtQuick import MyModule Window { width: 640 height: 480 visible: true property myValueType v: ({d: 4.4, e: "a string"}) Component.onCompleted: console.log(v) }
Compiler output
Warning: Main.qml:9:26: Could not compile binding for v: Cannot generate efficient code for DefineObjectLiteral [compiler] property myValueType v: ({d: 4.4, e: "a string"}) ^
Exhibit C: Where a JS object must have a specific structure as defined elsewhere in QML
Code (adapted from https://doc.qt.io/qt-6/qml-qtquick-tableview.html#qml-models )
import QtQuick import QtQuick.Controls.Fusion import Qt.labs.qmlmodels Window { width: 640 height: 480 visible: true TableView { anchors.fill: parent columnSpacing: 1 rowSpacing: 1 model: TableModel { TableModelColumn { display: "name" } TableModelColumn { display: "color" } rows: [ { "name": "cat", "color": "black" }, { "name": "dog", "color": "brown" }, { "name": "bird", "color": "white" } ] } delegate: TextField { required property string display text: display readOnly: true } } }
Compiler output
Warning: Main.qml:19:10: Could not compile binding for rows: Cannot generate efficient code for DefineObjectLiteral [compiler] rows: [ ^
Attachments
Issue Links
- duplicates
-
QTBUG-107469 qmlsc: Support DefineObjectLiteral
- Reported