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. TypeError on closing window
Forum Updated to NodeBB v4.3 + New Features

TypeError on closing window

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

    Hi All,

    Testing on windows [MSVC 19] with Qt 5.15.

    I've made a simple application to explain the problem: https://github.com/motters/QtSetContextProperty 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;
    vars.count(1);
    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.

    Thanks,

    Sam

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mottress
      wrote on last edited by
      #2

      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?

      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