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

C++-to-QML error handling



  • Hello!

    I have some questions regarding topic:

    1. Is there a common customization point, similar to QCoreApplication::notify, which would allow to handle/transform exceptions flying out of native code called by QML? notify allowed us to nicely handle all unexpected errors in our previous QWidgets-based project. Sadly, QML engine code seems to be not exception-neutral and crashes miserably if anything "flies" through it.
    2. Is there a way to obtain QML engine pointer from Q_INVOKABLE method which was called from QML, but its owning object was not created by QML?

    I've skimmed documentation, sources and Global exception handling with c++/QML topic regarding possible ways to properly handle errors which occur in QML+native codebase. Unfortunately it seems that error handling capabilities and overall integration between C++ and QML is rather limited, basically down to manual error codes. The closest one would have been QQmlObjectOrGadget::metacall - if I could override it globally somehow, augment with try-catch and transform caught exception into engine->throwError + return.

    Thanks


Log in to reply