Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Close Qml-Part and let the QWidget-App running

Close Qml-Part and let the QWidget-App running

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 515 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.
  • P Offline
    P Offline
    peter-70
    wrote on last edited by
    #1

    I have a QWidget App with a Qml Camera-Part. When I click on a Button in the QWidget-App, the Qml-Part will be loaded:

    Header:
    private:
        QQmlApplicationEngine engine;
    
    Implementation:
    QApplication a(argc, argv);
    
    MainWindow w;
    w.show();
    return a.exec();
    
    // MainWindow creates Recorder-instance and these calls the Load-method:
    
    void Recorder::Load() {
        this->engine.load(QUrl(QStringLiteral("qrc:/qml/recorder.qml")));
    

    When I am done with the recording of my media-files, I'm going to close the Qml-Part, but the QWidget- App should still running at all!

    I call this->engine.quit() in my C++ file, or Qt.quit() in my Qml-File, but either way the QWidget-App is closed also.

    How can I prevent this behavior?
    Ony the Qml Part should close, but not the QWidget App also.

    Thanks for help!

    J.HilkJ 1 Reply Last reply
    0
    • P Offline
      P Offline
      peter-70
      wrote on last edited by
      #2

      I think it's a pity that I have found little help in this forum so far. Neither to my own questions, nor by reading foreign contributions.

      Anyway ... I have a solution, but I do not know if it's not a bit dirty. When the signal is fired that a media stream is ready, I delete the recorder instance:

      void MainWindow::OnClosingPhotoRecorder(std::shared_ptr<QImage> photoImage)
      {
          some code goes here...
          this->recorder->deleteLater();
      }
      

      This deletion causes the Qml-object will close, but the QWidget app will continue to run.

      jsulmJ 1 Reply Last reply
      0
      • P peter-70

        I think it's a pity that I have found little help in this forum so far. Neither to my own questions, nor by reading foreign contributions.

        Anyway ... I have a solution, but I do not know if it's not a bit dirty. When the signal is fired that a media stream is ready, I delete the recorder instance:

        void MainWindow::OnClosingPhotoRecorder(std::shared_ptr<QImage> photoImage)
        {
            some code goes here...
            this->recorder->deleteLater();
        }
        

        This deletion causes the Qml-object will close, but the QWidget app will continue to run.

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @peter-70 said in Close Qml-Part and let the QWidget-App running:

        I think it's a pity that I have found little help in this forum so far.

        You asked 14h ago, please be more patient. People here help voluntary.
        Deleting the recorder should be fine.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P peter-70

          I have a QWidget App with a Qml Camera-Part. When I click on a Button in the QWidget-App, the Qml-Part will be loaded:

          Header:
          private:
              QQmlApplicationEngine engine;
          
          Implementation:
          QApplication a(argc, argv);
          
          MainWindow w;
          w.show();
          return a.exec();
          
          // MainWindow creates Recorder-instance and these calls the Load-method:
          
          void Recorder::Load() {
              this->engine.load(QUrl(QStringLiteral("qrc:/qml/recorder.qml")));
          

          When I am done with the recording of my media-files, I'm going to close the Qml-Part, but the QWidget- App should still running at all!

          I call this->engine.quit() in my C++ file, or Qt.quit() in my Qml-File, but either way the QWidget-App is closed also.

          How can I prevent this behavior?
          Ony the Qml Part should close, but not the QWidget App also.

          Thanks for help!

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @peter-70

          for(QObject *obj : engine.rootObjects()){
                  engine.rootObjects().removeOne(obj);
                  obj->deleteLater();
              }
              engine.clearComponentCache();
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved