Important: Please read the Qt Code of Conduct -

TypeError on closing window

  • Hi All,

    Testing on windows [MSVC 19] with Qt 5.15.

    I've made a simple application to explain the problem: open the project in QtCreator and run.

    Essentially I'm using "setContextProperty" to map across a C++ object to QML. See Test class here.

    Test vars;
    engine.rootContext()->setContextProperty("Test", &vars);

    I'm referencing the object in QLM as such

    Window {
        id: window
        visible: true
        width: 640
        height: 480
        title: Test.count

    This works perfectly fine on application boot & run, the data is mapped across as expected. However, when i close the application I get the following error:

    qrc:/main.qml:10: TypeError: Cannot read property 'count' of null

    Is there something I'm missing here? It's like QML is trying to access the Test object after it was deleted on exit.



  • I can confirm this is a lifetime issues. Moving "Test vars;" outside of main solves the issues.

    Does this mean QML engine is closing after the application thread?

Log in to reply