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

destroyed while one of its QML signal handlers is in progress



  • I have a StackView in my project and sometimes i push a new page or pop a page from that ... and it is working normally and fine.

    but sometimes in some pages i call a non return function (void) a from a c++ class (i defined it in public slots part in header) ... when i poping that page, if the function is not finished yet whole of the app crashes and write this error in output console:

    destroyed while one of its QML signal handlers is in progress.
    Most likely the object was deleted synchronously (use QObject::deleteLater() instead), or the application is running a nested event loop.
    This behavior is NOT supported!
    qrc:/Posts.qml:387: function() { [native code] }
    

    What's wrong with me?



  • finaly I fixed it myself:
    we can call function from another function with

    QMetaObject::invokeMethod
    

    In this way, qml item no longer waits for the cpp function to end,
    for example:

    void MyClass::functionA(QString url,QString allParams)
    {
        QMetaObject::invokeMethod( this, "functionAـreal",Qt::QueuedConnection, Q_ARG( QString, url ), Q_ARG( QString, allParams ));
    }
    
    void MyClass::functionAـreal(QString url,QString allParams)
    {
    .............. Things that take longer
    }
    

Log in to reply