Important: Please read the Qt Code of Conduct -

QQmlContext::setContextProperty() VS qmlRegisterSingletonType()

  • There are two ways, at least as far as I know, to expose a singleton instance from C++ to QML. One is to set the singleton instance as a context property with QQmlContext::setContextProperty() and the other one is to register a singleton type with qmlRegisterSingletonType and let QML create an instance.

    I've tried both ways and they're working perfectly well, and, I'm concerning about the overheads now.
    Because the C++ singleton object is a core engine of application, it will be accessed very frequently from QML side (in my plan), so I wonder which method is preferred in this case.
    I've read some performance tips but I couldn't find any issue related with this.
    Can I expect that both of them show similar performance? Or, Should I take one based on something?

Log in to reply