Solved Crash on exit when QMessageBox was used
-
Hi,
I'm trying to figure out a crash that occurs when I'm closing an application. The main window handles the close event and opens a QMessageBox to ask the user if he really wants to shut down.
Now, the application crashes in the destruction of the QApplication.
If I don't use the message box, the program shuts down nicely.I assembled a small test program to replicate the problem:
#include <QMainWindow> #include <QApplication> #include <QMessageBox> #include <QCloseEvent> class MyMainWindow : public QMainWindow { protected: void closeEvent( QCloseEvent* e) { if( QMessageBox::question( this, "foo", "bar") == QMessageBox::Yes) { e->accept(); } else { e->ignore(); } } }; int main( int argc, char** argv) { QApplication app( argc, argv); MyMainWindow window; window.show(); return app.exec(); }
The call stack can differ, but this would be one example:
#0 0x00007fffe843f195 in malloc_consolidate () from /lib64/libc.so.6 #1 0x00007fffe843fd31 in _int_free () from /lib64/libc.so.6 #2 0x00007ffff5cb3862 in ?? () from /usr/lib64/libQt5Gui.so.5 #3 0x00007ffff6c336d9 in QHashData::free_helper(void (*)(QHashData::Node*)) () from /usr/lib64/libQt5Core.so.5 #4 0x00007ffff5cae07c in ?? () from /usr/lib64/libQt5Gui.so.5 #5 0x00007fffe83febf9 in __run_exit_handlers () from /lib64/libc.so.6 #6 0x00007fffe83fec45 in exit () from /lib64/libc.so.6 #7 0x00007fffe83e8b0c in __libc_start_main () from /lib64/libc.so.6 #8 0x0000000000402a26 in _start () at ../sysdeps/x86_64/start.S:122
I tested this in two environments:
- SLES 12 with Qt 5.5.0 we built ourselves
- SLES 12 SP1 with Qt 5.5.1 from the repository
Compiler is always GCC 4.8
Any ideas would be appreciated.
-
@AndreasLubensky
Hello,
Your test application works fine on my setup (Qt 5.6.1, Debian stretch Linux 4.6.0 amd64). The stack looks like some static variable's cleanup crashes, but it's not clear which or where. Try running with 5.6.1 and see if the problem is still present.Kind regards.
-
I tested your code, It worked fine when i use Qt-kit with 5.5 with Vs2013. But it did not work well with Qt4.8.5 Vs 2008. When I use kit 4.8.5 I get
yes
button and its not closing at all. Both are for the same code.Try this code:
virtual void closeEvent(QCloseEvent* event) { event->ignore(); if (QMessageBox::Yes == QMessageBox::question(this, "Close Confirmation?", "Are you sure you want to exit?", QMessageBox::Yes | QMessageBox::No)) { event->accept(); }
-
I further investigated this and it seems to be related to the Qt libraries we link. Stripped down to only QtGui, QtCore, QtDBus, and QtWidgets everything works fine. In our actual environment we link many more, including both WebKit and WebEngine libraries. Might that cause some problems?
-
I figured it out, btw. We linked both libQt5QxcQpa and libQt5EglDeviceIntegration. For some reason libQt5EglDeviceIntegration has to come last, otherwise it crashes. And actually both libraries should not be explicitly linked at all.