[Development] QML Singletons

Mark markg85 at gmail.com
Tue Dec 11 10:23:27 CET 2012


On Tue, Dec 11, 2012 at 10:18 AM, Thomas Hartmann
<Thomas.Hartmann at digia.com> wrote:
> Hi,
>
>>
>> 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
> plugin.
>
> Singleton.qml would be the general entry point to instantiate QML
> singletons for a plugin.
>
> Singleton.qml
>
> Singletons {
>      MySingleton01 {
>          id: mySingleton01
>      }
>
>      MySingleton02 {
>          id: mySingleton02
>      }
>      QtObject {
>          id: mySingleton03
>      }
>      ...
> }
>
> Everything defined in Singletons would be instantiated once in the root
> context.
>
> Kind Regards,
> Thomas Hartmann
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development

Would this be an option:

singleton MyQmlComponent {
    ....
}

Where you can only have one MyQmlComponent within the application. A
second MyQmlComponent instance would result in some fancy error.
Just brainstorming :)



More information about the Development mailing list