Important: Please read the Qt Code of Conduct -

[SOLVED] Java + QApplication = Exception in qRemovePostRoutine!

  • So I'm having some trouble on cleanup. I have a Java app that, via JNI, invokes a Qt GUI from a DLL. I have a single global static object that, on construction, starts a thread with the requisite QApplication object and shows my GUI. Now, this all works great until I close the Java app. After that, at some point, the destructor in my static global object is called, which shuts down the thread (and yes I can confirm that the thread is truly finished), which in turn causes the QApplication object to go out of scope and be destroyed, and that should be the end of it, but I keep getting an exception in qRemovePostRoutine. I've tried every possible way I can think of to clean up, a dynamically created global object, catching the Java close event and manually shutting things down, etc, but nothing I do clears up the exception.

    Any help would be greatly appreciated.


  • After some more meddling I found that this happens even without the complications of Java and JNI and all that good stuff. Simply creating a Qt app that instantiates the QApplication object on some thread other than the main thread, even when you use the super secret QInternal::callFunction(QInternal::SetCurrentThreadToMainThread, 0), causes the exception. So the answer is just don't do that.

Log in to reply