qmlweb/qmlweb-parser

Singleton support

Closed this issue · 0 comments

Not sure if this belongs here or to the qmlweb project.

Singletons are an important design pattern for QML applications. They are most important for creating global style and configuration variables.

A workaround is to use global properties (referencing an item the parent context) e.g.

MyItem.qml

Item {
    color: style.blue1
}

MainWindow.qml

Item {

    QtObject {
        id: style
        readonly property color blue1: "#0000DD"
    }

    MyItem {
    }
}