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



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.