Important: Please read the Qt Code of Conduct -

Detaching Q_Property before QML Component has been destroying.

  • I got the Qml property which value is base on value passed from backend via reading Q_Property:

    property bool isFullScreen: System.Fullscreen

    Everythis worked fine, until I was needed to upgrade project to 5.14.2. Now when I'm closing application I got error:

    qrc:/qml/main.qml:13: TypeError: Cannot read property 'Fullscreen' of null

    No I'm trying to figure out how can if thats happen. I was trying to use Component.onDestruction , but it is emited after backend has been detached from qml front.

    Also I was trying this:

    property bool isFullScreen: 
     if (Component.status === Component.Ready)
          return System.Fullscreen 
        return false

    But the Component is binding only to false

    Any idea?

  • Moderators

    Your backend gets destroyed before QML does. The solution is usually to rearrange how you initialise things in your main.cpp. Make sure backend outlives the engine and you won't see these errors (btw. they are completely harmless).

  • Hi @sierdzio I was thinking about it but not sure how to do that.

    Currently I just have the Connection between QApplication signal and my backend slot to clean befor quiting the App.

    I was trying to add

    QObject::connect(&app, &QApplication::aboutToQuit, [&engine, &system] {  engine.quit(); system.disconnect(); )};

    But it doesn't change anything. I guess there should be a method to stop engine but can't find in docs

    Am I doing something wrong or maybe you know how the enginge should be stopped?

  • Moderators

    You can parent your QObjects to QML engine and Qt will clean it up for you.

    QQmlEngine engine;
    So something like: auto system = new System(&engine);
    engine.rootContext()->setContextProperty("System",  system);

  • @sierdzio Hmm.. that's how I connected them and somehow from 5.14.x this isn't working correctly.

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("theSystem", integrator->system());

  • Moderators

    Yeah, but where is that integrator created? What manages it's lifetime?

Log in to reply