No assert when the focus changes and a window has no active focus item.
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Fri, 22 Nov 2013 18:13:20 +0000 (19:13 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 25 Nov 2013 16:32:12 +0000 (17:32 +0100)
[ChangeLog][QtQuick] Fix crash when showing and hiding a window that has
no active focus item.
QtQuickControls hit the situation where a popup window was shown without
ever having an active focus item. When then closing the popup,
clearFocusInScope would assume it had to always modify the old focus,
but in this case the focus would be on the window itself, so there is
nothing to update.

Task-number: QTBUG-35057

Change-Id: Ifbde4689d39f98b13e6f90573cb22e28bb86f2c4
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Liang Qi <liang.qi@digia.com>
src/quick/items/qquickwindow.cpp

index 796ddcf..848eeca 100644 (file)
@@ -771,23 +771,24 @@ void QQuickWindowPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
         oldActiveFocusItem = activeFocusItem;
         newActiveFocusItem = scope;
 
-        Q_ASSERT(oldActiveFocusItem);
-
 #ifndef QT_NO_IM
         qApp->inputMethod()->commit();
 #endif
 
         activeFocusItem = 0;
-        QFocusEvent event(QEvent::FocusOut, reason);
-        q->sendEvent(oldActiveFocusItem, &event);
 
-        QQuickItem *afi = oldActiveFocusItem;
-        while (afi && afi != scope) {
-            if (QQuickItemPrivate::get(afi)->activeFocus) {
-                QQuickItemPrivate::get(afi)->activeFocus = false;
-                changed << afi;
+        if (oldActiveFocusItem) {
+            QFocusEvent event(QEvent::FocusOut, reason);
+            q->sendEvent(oldActiveFocusItem, &event);
+
+            QQuickItem *afi = oldActiveFocusItem;
+            while (afi && afi != scope) {
+                if (QQuickItemPrivate::get(afi)->activeFocus) {
+                    QQuickItemPrivate::get(afi)->activeFocus = false;
+                    changed << afi;
+                }
+                afi = afi->parentItem();
             }
-            afi = afi->parentItem();
         }
     }