Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QQmlContext::setContextProperty() VS qmlRegisterSingletonType()
Qt 6.11 is out! See what's new in the release blog

QQmlContext::setContextProperty() VS qmlRegisterSingletonType()

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xylosper
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved