Am 23.04.2020 11:39 schrieb David Llewellyn-Jones:

https://gist.github.com/pazdera/1098119

Yeah, this looks like a decent example: clear and complete.

As you can see from this, you essentially end up with a global object
you can access from anywhere. The downside is that you only ever have
one of them, so if you need more than one Controller, or (as Julian
mentions) think it might be needed in future, then this probably isn't
the right approach.
Right now it works with single objects (one controller, one netaccess, one imgdb), which are instanciated in c++, but they are not defined as singletons. So my first step could be, to redefine the class as singletons, adapt the references accordingly and see what happens.


I hope this also works for Q_OBJECT s.
Maybe I should rather make netAccess and imgDB itself singletons?

I don't recall any issues with Q_OBJECTS being singletons, however if
you plan to use it in your QML you may also need to do some work
registering it as a singleton there too.

There's an example here:

https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterSingletonType

But I wouldn't worry about this unless you're already registering your
Controller as a QML type and need to use it from QML. As Julien also
pointed out, mixing singletons in C++ and QML adds complexity that can
lead to errors.

I'd like to avoid that and only interact with the singletons inside c++.

Thanks a lot to you and Julien,
fooxl.
_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Reply via email to