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. How would one ensure destructor call of a Singleton, which might be used in Qml or not?
Qt 6.11 is out! See what's new in the release blog

How would one ensure destructor call of a Singleton, which might be used in Qml or not?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 676 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.
  • C Offline
    C Offline
    c64zottel
    wrote on last edited by
    #1

    A Singleton to use in QML is registered via qmlRegisterSingletonType. The Qml engine takes responsible to call the destructor thats why we instanciate the Singleton somewhat like this:

    static QObject * instance(QQmlEngine *, QJSEngine *) {
        static UserInputManagement * uim = 0;
        if( not uim ) uim = new UserInputManagement;
        return uim;
    }
    

    But if we want to use such a Singleton as gate to a library than we don't know if the client uses it in a QML context or not.

    How to ensure the destructor is called, either way?

    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