[Development] QML Singletons

Thomas Hartmann Thomas.Hartmann at digia.com
Tue Dec 11 10:18:30 CET 2012


> it's a bit weird that you need a qmldir for that. Wouldn't it be better if we could mark this as singleton in the implementation (ie. inside single.qml)? Maybe use a new keyword for that? static is already a reserved keyword in Ecmascript 5.1, so we could maybe write single.qml as:
> static QtObject {
> 	property int myproperty;
> 	...
> }

But how would the engine know about single.qml being static? AFAIK all 
.qml parsing is done on demand. The engine would have to know that 
single.qml is a singleton from another source (Or scan all .qml files 
upfront for the static keyword).

Another approach could be having something like a Singleton.qml in the 

Singleton.qml would be the general entry point to instantiate QML 
singletons for a plugin.


Singletons {
     MySingleton01 {
         id: mySingleton01

     MySingleton02 {
         id: mySingleton02
     QtObject {
         id: mySingleton03

Everything defined in Singletons would be instantiated once in the root 

Kind Regards,
Thomas Hartmann

More information about the Development mailing list