Close Qml-Part and let the QWidget-App running



  • 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!



  • 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.


  • Moderators

    @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.



  • @peter-70

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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.