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. How to Keep the Backend CPP Application Running and Kill the Frontend QML Engine
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 1.1k 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.
  • C Offline
    C Offline
    codemonkeyboris
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • C Offline
        C Offline
        codemonkeyboris
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shaan7
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            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 ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • C Offline
              C Offline
              codemonkeyboris
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                codemonkeyboris
                wrote on last edited by
                #7

                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

                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