My original question was posted 11 days ago. Since it did not get a definitive answer, I posted a reformulated version (with some additions about where the error occurs and the corresponding message) on another forum. I thought it would be of interest for the readers of my original question to also post the reformulated version here (it feels a bit awkward now). Anyway, I got an answer. Here it is:
https://forum.qt.io/post/824619
Thanks everyone for your time.
@AhmedAEK: I had made an attempt using multiprocessing
before trying the approach above using QApplication deletion that I thought would be a simpler option. It was half-working. Now that I know this simpler approach cannot work, I will go back to the multiprocessing
version. Thanks for your suggestion which encourages me to do so.