Commit 67f58920 authored by Alan Alpert's avatar Alan Alpert Committed by Qt by Nokia

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: default avatarMartin Jones <martin.jones@nokia.com>
parent 1c7b0362
......@@ -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);
......@@ -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;
......
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()
}
}
}
......@@ -138,6 +138,7 @@ private slots:
void scopedFocus();
void addedToCanvas();
void changeParent();
void multipleFocusClears();
void constructor();
void setParentItem();
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment