[Interest] sharing singleton instance between C++ and QML

Stefan Seefeld stefan at seefeld.name
Wed Oct 25 19:49:08 CEST 2023


Hello,

I'm trying to "modernize" a large code base that just migrated from Qt5 to
Qt6.
Our code is using a few singleton objects that used to be exported into the
QML runtime via `qmlRegisterSingletonInstance()`. But as it is now
recommended to move away from `qmlRegisterType()` (in favour of letting the
QML Module creation infrastructure take care of this), I'm expecting
`qmlRegisterSingletonInstance()` also to be deprecated.

I did find https://doc.qt.io/qt-6/qtqml-cppintegration-exposecppstate.html
and its use of `QMLEngine::singletonInstance<...>(...)` to access a QML
singleton from C++, this method requires my singleton code to be aware of
the `QMLEngine` object. Is there a way to do the inverse, i.e. register a
C++ function (pointer) through which the `QMLEngine` would access the
singleton, just as was the case with `qmlRegisterSingletonInstance()` ?

Thanks,

-- 

      ...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231025/2389af7a/attachment.htm>


More information about the Interest mailing list