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

How to Keep the Backend CPP Application Running and Kill the Frontend QML Engine



  • Hi Forum,

    We would like to reconfigure our frontend QML on the fly sometimes without shutting down the whole application.

    I tried calling the quit() function from the QQmlApplicationEngine class and it exits the whole application.

    I also tried to unload one of my qml page by putting a Loader in it and assign the {} (empty string/undefined) to it but I got following error:

                  qrc:/main.qml:30: Error: Cannot assign QJSValue to QQmlComponent*
    

    Is there any other proper way to shwodown the QML engine or unload pages from the QML engine?

    Thank you very much!


  • Qt Champions 2017

    If you want split the application you need to make them as two independent process(back-end process and front-end process). Need to make some way of communicating between the front end app and backend app. Also show the code line which gives the error.



  • Thanks for the prompt reply.

    Here are the codes with the error:

    import QtQuick 2.7
    import QtQuick.Window 2.2
    
    import QtQuick.Controls 2.0
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Layouts 1.3
    import Test 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        id: mainWindow
    
        Loader {
            id: loader
            objectName: "loader"
            anchors.centerIn: parent
            sourceComponent: Common.getComponent(mainWindow)    <== error: Unable to assign QQmlComponent to QUrl
        }
    
        Timer
        {
            id: textTimer
            interval: 10000
            repeat: false
            running: true
            triggeredOnStart: true
            onTriggered: loader.sourceComponent = {}  <== error: Unable to assign QQmlComponent to QUrl
        }
    }
    

    As you can see, both doing this from the front end and the back end gives the same error.

    And how am I suppose to split the application in to two? Just have two qt programs running and have an IPC communication in between? The reason why we are trying to dynamically load and unload the QML pages is to avoid this.



  • You don't need to maintain two separate processes. How are you loading the QML UI? If you are using QQmlApplicationEngine and its load function, you can simply delete the QQmlApplicationEngine instance, create a new one and load your QML in that again.


  • Qt Champions 2017

    Do you want just unload some qml ? Are you hitting the error when try doing it ? Can tell me what does that common.getcomponent returns ? Show me the method details. Looks like you are returning qml file path one you call the function. Can you confirm ?



  • Hi Shann,

    Been there but didn't work.

    I made the QQmlApplicationEngine *engine; public from main and when I deleted it or calling the quit() function, the whole application is killed.

    Thanks.



  • I think I figured it out.

    Instead of using {} or "" I just need to use "undefined". Yes the word directly.

    The following doc is out of date:
    http://doc.qt.io/qt-5/qml-var.html


Log in to reply