QMessageBox crash on close
-
Environment
- Qt Version: 6.11.1
- Platform: fedora44 (X11 / Wayland with KDE)
- Compiler: gcc 16.1.1 20260515
Summary
When clicking the close button (X) on a native QMessageBox (e.g., QMessageBox::about()),
the application crashes with SIGSEGV at QDialogPrivate::setNativeDialogVisible().Root Cause
In QDialogPrivate::setNativeDialogVisible() (qtbase/src/widgets/dialogs/qdialog.cpp):
bool QDialogPrivate::setNativeDialogVisible(bool visible) { if (QPlatformDialogHelper *helper = platformHelper()) { if (visible) { // ... nativeDialogInUse = helper->show(...); // ✅ properly assigned } else if (nativeDialogInUse) { helper->hide(); // ❌ nativeDialogInUse is NEVER set to false here } } return nativeDialogInUse; }Crash Sequence
- User clicks X on native QMessageBox
- → done() → setVisible(false) → setNativeDialogVisible(false)
- → helper->hide() is called (1st time) — platform resources freed
- → BUT nativeDialogInUse remains true
- → exec() returns, QMessageBox stack variable destroyed
- → ~QDialog() calls hide() → setVisible(false) → setNativeDialogVisible(false)
- → nativeDialogInUse is still true → helper->hide() called AGAIN (2nd time)
- → Accessing already-destroyed native dialog resources → SIGSEGV
Backtrace
Core was generated by `./test_about'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000000020 in ?? ()
[Current thread is 1 (Thread 0x7f94be9a0600 (LWP 278630))]
#0 0x0000000000000020 in ??? ()
#1 0x00007f94c0d19904 in QDialogPrivate::setNativeDialogVisible(bool) () at /lib64/libQt6Widgets.so.6
#2 0x00007f94c0d5337b in QMessageBoxPrivate::setVisible(bool) () at /lib64/libQt6Widgets.so.6
#3 0x00007f94c0d18e9d in QDialog::~QDialog() () at /lib64/libQt6Widgets.so.6
#4 0x00007f94c0d521e5 in QMessageBox::~QMessageBox() () at /lib64/libQt6Widgets.so.6
#5 0x00007f94c0d1ab5a in QDialog::exec() () at /lib64/libQt6Widgets.so.6
#6 0x00007f94c0d55922 in QMessageBox::about(QWidget*, QString const&, QString const&) () at /lib64/libQt6Widgets.so.6
#7 0x00000000004005c2 in main::{lambda()#1}::operator()() const ()
#8 0x0000000000400a0b in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, main::{lambda()#1}>::call(main::{lambda()#1}&, void**)::{lambda()#1}::operator()() const ()
#9 0x0000000000400a68 in void QtPrivate::FunctorCallBase::call_internal<void, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, main::{lambda()#1}>::call(main::{lambda()#1}&, void**)::{lambda()#1}>(void**, QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, main::{lambda()#1}>::call(main::{lambda()#1}&, void**)::{lambda()#1}&&) ()
#10 0x0000000000400a41 in QtPrivate::FunctorCall<std::integer_sequence<unsigned long>, QtPrivate::List<>, void, main::{lambda()#1}>::call(main::{lambda()#1}&, void**) ()
#11 0x00000000004009ed in void QtPrivate::FunctorCallablemain::{lambda()#1}::call<QtPrivate::List<>, void>(main::{lambda()#1}&, void*, void**) ()
#12 0x00000000004009ad in QtPrivate::QCallableObject<main::{lambda()#1}, QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) ()
#13 0x00007f94bf784eb7 in void doActivate<false>(QObject*, int, void**) () at /lib64/libQt6Core.so.6
#14 0x00007f94c0b9fdba in QAbstractButton::clicked(bool) () at /lib64/libQt6Widgets.so.6
#15 0x00007f94c0ba0049 in QAbstractButtonPrivate::emitClicked() () at /lib64/libQt6Widgets.so.6
#16 0x00007f94c0ba19d6 in QAbstractButtonPrivate::click() () at /lib64/libQt6Widgets.so.6
#17 0x00007f94c0ba1c2d in QAbstractButton::mouseReleaseEvent(QMouseEvent*) () at /lib64/libQt6Widgets.so.6
#18 0x00007f94c0ab0778 in QWidget::event(QEvent*) () at /lib64/libQt6Widgets.so.6
#19 0x00007f94c0a3f92e in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib64/libQt6Widgets.so.6
#20 0x00007f94c0a4aa26 in QApplication::notify(QObject*, QEvent*) () at /lib64/libQt6Widgets.so.6
#21 0x00007f94bf70f7b8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib64/libQt6Core.so.6
#22 0x00007f94c0a49139 in QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool, bool) ()
at /lib64/libQt6Widgets.so.6
#23 0x00007f94c0ac6d84 in QWidgetWindow::handleMouseEvent(QMouseEvent*) () at /lib64/libQt6Widgets.so.6
#24 0x00007f94c0ac983b in QWidgetWindow::event(QEvent*) () at /lib64/libQt6Widgets.so.6
#25 0x00007f94c0a3f92e in QApplicationPrivate::notify_helper(QObject*, QEvent*) () at /lib64/libQt6Widgets.so.6
#26 0x00007f94bf70f7b8 in QCoreApplication::notifyInternal2(QObject*, QEvent*) () at /lib64/libQt6Core.so.6
#27 0x00007f94bff0638f in QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*) () at /lib64/libQt6Gui.so.6
#28 0x00007f94bff7802c in QWindowSystemInterface::sendWindowSystemEvents(QFlagsQEventLoop::ProcessEventsFlag) () at /lib64/libQt6Gui.so.6
#29 0x00007f94c0561f84 in userEventSourceDispatch(_GSource*, int ()(void), void*) () at /lib64/libQt6Gui.so.6
#30 0x00007f94bed92f24 in g_main_context_dispatch_unlocked.lto_priv () at /lib64/libglib-2.0.so.0
#31 0x00007f94bed97038 in g_main_context_iterate_unlocked.isra () at /lib64/libglib-2.0.so.0
#32 0x00007f94bed971e3 in g_main_context_iteration () at /lib64/libglib-2.0.so.0
#33 0x00007f94bfa69a9d in QEventDispatcherGlib::processEvents(QFlagsQEventLoop::ProcessEventsFlag) () at /lib64/libQt6Core.so.6
#34 0x00007f94bf71d57b in QEventLoop::exec(QFlagsQEventLoop::ProcessEventsFlag) () at /lib64/libQt6Core.so.6
#35 0x00007f94bf718992 in QCoreApplication::exec() () at /lib64/libQt6Core.so.6
#36 0x0000000000400758 in main ()Minimal Reproducer (C++20 / Qt6)
#include <QApplication> #include <QMainWindow> #include <QMessageBox> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow window; auto *btn = new QPushButton("Open About", &window); QObject::connect(btn, &QPushButton::clicked, &window, [&window]() { QMessageBox::about(&window, "About", "About"); }); window.resize(300, 200); window.show(); return app.exec(); }Proposed Fix
} else if (nativeDialogInUse) { helper->hide(); nativeDialogInUse = false; // ← ADD THIS LINE }Workaround
app.setAttribute(Qt::AA_DontUseNativeDialogs, true);
-
If you want to report bugs you should do it here: https://qt-project.atlassian.net/jira/projects?page=1&sortKey=name&sortOrder=ASC
-
If you want to report bugs you should do it here: https://qt-project.atlassian.net/jira/projects?page=1&sortKey=name&sortOrder=ASC
-
@jsulm The Qt Bug Tracker website is extremely cumbersome to use. After logging in, I lack the permissions to create bug reports, so I’m posting the issue here instead.
@jackfafa said in QMessageBox crash on close:
@jsulm The Qt Bug Tracker website is extremely cumbersome to use. After logging in, I lack the permissions to create bug reports, so I’m posting the issue here instead.
When I log in, there's a yellow banner at the top of the page that says:
For troubleshooting and support, please contact jira-admin@qt-project.org.
-
@jsulm The Qt Bug Tracker website is extremely cumbersome to use. After logging in, I lack the permissions to create bug reports, so I’m posting the issue here instead.
@jackfafa said in QMessageBox crash on close:
After logging in, I lack the permissions to create bug reports
Please try navigating to https://qt-project.atlassian.net/jira/your-work Do you get the required permissions now?
(Reference: https://wiki.qt.io/Jira_Cloud_migration#First_time_users )