Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't assert if focus is already clear.
Already cleared focus should exit the function without terminating the
runtime.

Task-number: QTBUG-24714
Change-Id: Ia8c6be0d88e43d1f71112acc7bac3eb674f22de8
Reviewed-by: Martin Jones <martin.jones@nokia.com>
  • Loading branch information
Alan Alpert authored and Qt by Nokia committed Mar 15, 2012
1 parent 1c7b036 commit 67f5892
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/quick/items/qquickcanvas.cpp
Expand Up @@ -607,7 +607,6 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
{
Q_Q(QQuickCanvas);

Q_UNUSED(item);
Q_ASSERT(item);
Q_ASSERT(scope || item == rootItem);

Expand All @@ -618,7 +617,12 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
qWarning() << " activeFocusItem:" << (QObject *)activeFocusItem;
#endif

QQuickItemPrivate *scopePrivate = scope ? QQuickItemPrivate::get(scope) : 0;
QQuickItemPrivate *scopePrivate = 0;
if (scope) {
scopePrivate = QQuickItemPrivate::get(scope);
if ( !scopePrivate->subFocusItem )
return;//No focus, nothing to do.
}

QQuickItem *oldActiveFocusItem = 0;
QQuickItem *newActiveFocusItem = 0;
Expand Down
18 changes: 18 additions & 0 deletions tests/auto/quick/qquickitem/data/multipleFocusClears.qml
@@ -0,0 +1,18 @@
import QtQuick 2.0

Rectangle {
width: 200
height: 200

FocusScope {
id: focusScope
anchors.fill: parent

TextInput {
anchors.centerIn: parent
text: "Some text"
onActiveFocusChanged: if (!activeFocus) focusScope.focus = false
Component.onCompleted: forceActiveFocus()
}
}
}
11 changes: 11 additions & 0 deletions tests/auto/quick/qquickitem/tst_qquickitem.cpp
Expand Up @@ -138,6 +138,7 @@ private slots:
void scopedFocus();
void addedToCanvas();
void changeParent();
void multipleFocusClears();

void constructor();
void setParentItem();
Expand Down Expand Up @@ -675,6 +676,16 @@ void tst_qquickitem::changeParent()

}

void tst_qquickitem::multipleFocusClears()
{
//Multiple clears of focus inside a focus scope shouldn't crash. QTBUG-24714
QQuickView *view = new QQuickView;
view->setSource(testFileUrl("multipleFocusClears.qml"));
view->show();
ensureFocus(view);
QTRY_VERIFY(QGuiApplication::focusWindow() == view);
}

void tst_qquickitem::constructor()
{
QQuickItem *root = new QQuickItem;
Expand Down

0 comments on commit 67f5892

Please sign in to comment.