diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-20 10:34:22 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-11-20 10:38:50 (GMT) |
commit | f8fb064d6b2ad55c66ce1a481e7f829278051fcb (patch) | |
tree | f9757d37597cd9836a080c979899fd7a5417b49e | |
parent | 8fb9ed08c60b667737a9ae1b209da61fe9c67200 (diff) | |
download | Qt-f8fb064d6b2ad55c66ce1a481e7f829278051fcb.zip Qt-f8fb064d6b2ad55c66ce1a481e7f829278051fcb.tar.gz Qt-f8fb064d6b2ad55c66ce1a481e7f829278051fcb.tar.bz2 |
avoid possible crash when showing a modal dialog from a widget destructor
Task-number: QTBUG-5804
Reviewed-by: denis
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 5 | ||||
-rw-r--r-- | tests/auto/qwidget/tst_qwidget.cpp | 25 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 709f6f3..fbb9115 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -8248,7 +8248,8 @@ bool QWidget::event(QEvent *event) QList<QObject*> childList = d->children; for (int i = 0; i < childList.size(); ++i) { QObject *o = childList.at(i); - QApplication::sendEvent(o, event); + if (o) + QApplication::sendEvent(o, event); } } update(); @@ -8277,7 +8278,7 @@ bool QWidget::event(QEvent *event) QList<QObject*> childList = d->children; for (int i = 0; i < childList.size(); ++i) { QObject *o = childList.at(i); - if (o != QApplication::activeModalWidget()) { + if (o && o != QApplication::activeModalWidget()) { if (qobject_cast<QWidget *>(o) && static_cast<QWidget *>(o)->isWindow()) { // do not forward the event to child windows, // QApplication does this for us diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 9692c6e..1e3f5f8 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -384,6 +384,8 @@ private slots: void activateWindow(); + void openModal_taskQTBUG_5804(); + #ifdef Q_OS_SYMBIAN void cbaVisibility(); #endif @@ -9583,6 +9585,29 @@ void tst_QWidget::activateWindow() QTRY_VERIFY(!mainwindow2->isActiveWindow()); } +void tst_QWidget::openModal_taskQTBUG_5804() +{ + class Widget : public QWidget + { + public: + Widget(QWidget *parent) : QWidget(parent) + { + } + ~Widget() + { + QMessageBox msgbox; + QTimer::singleShot(10, &msgbox, SLOT(accept())); + msgbox.exec(); //open a modal dialog + } + }; + + QWidget *win = new QWidget; + new Widget(win); + win->show(); + QTest::qWaitForWindowShown(win); + delete win; +} + #ifdef Q_OS_SYMBIAN void tst_QWidget::cbaVisibility() { |