ubports / ubuntu-ui-toolkit

Moved to https://gitlab.com/ubports/core/lomiri-ui-toolkit
https://gitlab.com/ubports/core/lomiri-ui-toolkit
GNU Lesser General Public License v3.0
13 stars 21 forks source link

[Qt 5.12+] Importing Ubuntu.Components breaks JS Object in QML #95

Closed dobey closed 4 years ago

dobey commented 4 years ago

Simply importing the Ubuntu.Components plugin results in breaking the JavaScript handling in Qt, such that things like Object.keys() no longer works. For example, the following script will show different behavior by simply commenting the import Ubuntu.Components 1.3 line, when running on Qt 5.12 or newer:

import QtQuick 2.4
import Ubuntu.Components 1.3

Item {
    property var sortByModel: {
        "timestamp": "Sort by timestamp",
        "title": "Sort by title"
    }

    Component.onCompleted: console.log(Object.keys(sortByModel))
}
dobey commented 4 years ago

Tagging @z3ntu for this too, as it was mentioned in another PR that this was happening on 5.14/5.15 on Alpine/pmOS.

z3ntu commented 4 years ago

Yeah, another easier example from https://github.com/ubports/ubuntu-ui-toolkit/pull/83#issuecomment-645003685

$ ./tests/Gallery/gallery test1.qml
qml: Object.prototype: undefined
^C
$ ./tests/Gallery/gallery test2.qml
qml: Object.prototype: [object Object]
^C
==> test1.qml <==
import QtQuick 2.4
import Ubuntu.Components 1.3

Item {
    Component.onCompleted: {
        console.log("Object.prototype: " + Object.prototype);
    }
}

==> test2.qml <==
import QtQuick 2.4

Item {
    Component.onCompleted: {
        console.log("Object.prototype: " + Object.prototype);
    }
}

Also

Works fine in Qt 5.11 so it's a Qt 5.12 breakage

dobey commented 4 years ago

OK. This is fixed now in the xenial_-_qt-5-12 branch. The cause was uitk having an Object.qml (that was not documented and only meant for internal uses), combined with the following change in Qt 5.12.0 release:

   * [QTBUG-51581] Properties of the JS global object will now be looked up
     after local properties in the QML object. This can lead to runtime
     incompatibilities if your qml file is named the same as a property of
     the global object (e.g. Date.qml).

The Object was also being used in unity8, which I've also changed to not use any more in its xenial_-_qt-5-12 branch.