[Interest] How to get instance of qml singleton on C++ side

Ben Lau xbenlau at gmail.com
Sun Jan 14 10:41:57 CET 2018


You may take this piece of code as an example:

https://github.com/benlau/quickflux/blob/master/qfappdispatcher.cpp#L51

On 14 January 2018 at 17:09, Лагнер, Сергей <developer at lagner.ru> wrote:

> Hello all.
> I have two classes registered as qml singletons.
>
>
> QObject * First::create(QQmlEngine*, QJSEngine*) {
> return new First();
> }
>
> QObject * Second::create(QQmlEngine*, QJSEngine*) {
> return new Second();
> }
>
> qmlRegisterSingletonType<First>("com.example", 1, 0, "First",
> &First::create);
> qmlRegisterSingletonType<Second>("com.example", 1, 0, "Second",
> &Second::create);
>
>
>
> Now I'd like to have an access to one of them from another.
> For example
>
> void Second::method() {
> // I need First * instance here
> }
>
> Is there any way to get qml singleton instance on C++ side, from
> QQmlEngine or something?
>
> ---
> Have a nice day.
> Sergey
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180114/bb7bd52f/attachment.html>


More information about the Interest mailing list