diff --git a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp index 752b9e7c20..146b114389 100644 --- a/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp +++ b/src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp @@ -169,7 +169,9 @@ void QWindowsAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) // An event has to be associated with a window, // so find the first parent that is a widget and that has a WId QAccessibleInterface *iface = event->accessibleInterface(); - QWindow *window = iface ? QWindowsAccessibility::windowHelper(iface) : 0; + if (!iface) // ### This should not happen, maybe make it an assert. + return; + QWindow *window = QWindowsAccessibility::windowHelper(iface); delete iface; if (!window) { diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index 5c8d3e3a57..2b8e1a7036 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -205,6 +205,7 @@ QAccessibleWidget::QAccessibleWidget(QWidget *w, QAccessible::Role role, const Q /*! \reimp */ QWindow *QAccessibleWidget::window() const { + Q_ASSERT(widget()); return widget()->windowHandle(); } @@ -343,6 +344,7 @@ QAccessibleWidget::relations(QAccessible::Relation match /*= QAccessible::AllRel /*! \reimp */ QAccessibleInterface *QAccessibleWidget::parent() const { + Q_ASSERT(widget()); QObject *parentWidget= widget()->parentWidget(); if (!parentWidget) parentWidget = qApp; @@ -352,6 +354,7 @@ QAccessibleInterface *QAccessibleWidget::parent() const /*! \reimp */ QAccessibleInterface *QAccessibleWidget::child(int index) const { + Q_ASSERT(widget()); QWidgetList childList = childWidgets(widget()); if (index >= 0 && index < childList.size()) return QAccessible::queryAccessibleInterface(childList.at(index)); diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index f5f336ed64..ce8032e0c3 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -364,6 +364,24 @@ void tst_QAccessibility::eventTest() QVERIFY(QTestAccessibility::containsEvent(&hideEvent)); delete button; + + // Make sure that invalid events don't bring down the system + // these events can be in user code. + QWidget *widget = new QWidget(); + QAccessibleEvent ev1(widget, QAccessible::Focus); + QAccessible::updateAccessibility(&ev1); + + QAccessibleEvent ev2(widget, QAccessible::Focus); + ev2.setChild(7); + QAccessible::updateAccessibility(&ev2); + delete widget; + + QObject *object = new QObject(); + QAccessibleEvent ev3(widget, QAccessible::Focus); + QAccessible::updateAccessibility(&ev3); + delete object; + + QTestAccessibility::clearEvents(); }