Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Application crashing on closing the window Application



  • Hi,

    I have a QT C++ singleton class, in which we have a QMLProperty and invokable function, hence registered this class as qmlRegisterSingletonType in main.cpp and using the class object in my qml.
    On closing the application, the application crashes.
    the singleton class return the address of a static object of the class.
    getInstance function:
    static myclass myclassObj;
    return &myclassObj;

    Is the above code wrong ? because if i don't use the class object in qml, qt exits neatly with code exited with 0.

    Using Qt MSVC compiler to compile and run the application.

    @JKSH @dheerendra @J-Hilk


  • Moderators

    @Anita can you show us the getter functions and the destructor.

    Who is supposed to manage the lifetime of the singleton, QML or c++?



  • @J-Hilk

    Hi,

    The destructor is empty.

    using a Q_INVOKABLE fn :
    Q_INVOKABLE bool getvalue(){ return true;}

    in main.cpp :
    registered the object using:
    qmlRegisterSingletonType<testinginstance>("Test", 1, 0, "Test",getInstance);

    in main.qml:
    import Test 1.0
    property bool value : Test.getvalue()


  • Qt Champions 2017

    if you can post your sample completely, it will help us to help you


Log in to reply