In my understanding, it is not so much of the random destruction order or QObject's, but that all QObject's in Python has to be destructed before QCoreApplication. PyQt already solved it if the QCoreApplication is created from the Python side, by ensuring all QObject's destruction before QCoreApplication. but since in our case QCoreApplication is not created from Python, their solution doesn't do anything for us.
In our case, the KritaPyQtPlugin destructor (and thus PyKrita::finalize) is called during the destructor of QCoreApplication, which might be triggering UB? So I wonder if the proper way to clean up is to call PyKrita::finalize earlier, perhaps we can use the QCoreApplication::aboutToQuit signal?
In my understanding, it is not so much of the random destruction order or QObject's, but that all QObject's in Python has to be destructed before QCoreApplication. PyQt already solved it if the QCoreApplication is created from the Python side, by ensuring all QObject's destruction before QCoreApplication. but since in our case QCoreApplication is not created from Python, their solution doesn't do anything for us.
In our case, the KritaPyQtPlugin destructor (and thus PyKrita::finalize) is called during the destructor of QCoreApplication, which might be triggering UB? So I wonder if the proper way to clean up is to call PyKrita::finalize earlier, perhaps we can use the QCoreApplicatio n::aboutToQuit signal?