[Development] QTCS2019 Notes from QtQml session

Damian Ivanov damianatorrpm at gmail.com
Fri Nov 22 18:32:48 CET 2019


Hello Giuseppe,

>> qmlRegisterSingletonInstance("Utils", 3, 14, "Obj", obj);
>In 5.14 the solution is something along the lines of
Exactly what I was looking for.

>In pre-5.14 the same is achieved by using qmlRegisterSingletonType with
>a callback (that returns the object + sets the ownership of the object
>to C++; definitely not as convenient). Usage from QML is identical.
I was using context properties and were not that in-depth with the singletons.
I did read the great Qt documentation on them, maybe I have missed that.
Thanks for pointing it out.

On Fri, Nov 22, 2019 at 7:14 PM Giuseppe D'Angelo via Development
<development at qt-project.org> wrote:
>
> Il 22/11/19 16:49, Damian Ivanov ha scritto:
> > I don't see this anywhere documented how this could be done using a singleton.
>
> In 5.14 the solution is something along the lines of
>
> > qmlRegisterSingletonInstance("Utils", 3, 14, "Obj", obj);
>
> then in QML
>
> > import Utils 3.14
> > // use "Obj" instead of "obj"
>
> In pre-5.14 the same is achieved by using qmlRegisterSingletonType with
> a callback (that returns the object + sets the ownership of the object
> to C++; definitely not as convenient). Usage from QML is identical.
>
>
> > If I register it as singleton the application_engine doesn't find it
> > findChild->
>
> Could you please elaborate on this point?
>
>
> Thanks,
> --
> Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
> KDAB (France) S.A.S., a KDAB Group company
> Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
> KDAB - The Qt, C++ and OpenGL Experts
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development


More information about the Development mailing list