diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-01-06 14:27:42 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2010-01-06 14:46:14 (GMT) |
commit | 70496884450d3989829a63baac8db48d36190a25 (patch) | |
tree | 50c584b0dc465772b8968f34a6b1f6ea2c29ded8 /tests | |
parent | a24d87f6469fa491624590383617b43c2b3dda32 (diff) | |
download | Qt-70496884450d3989829a63baac8db48d36190a25.zip Qt-70496884450d3989829a63baac8db48d36190a25.tar.gz Qt-70496884450d3989829a63baac8db48d36190a25.tar.bz2 |
Fixes a crash when setting focus on a widget with a focus proxy.
When the focus proxy widget doesn't have InputMethodEnabled attribute set we
shouldn't try to set an input context on it.
Reviewed-by: Simon Hausmann
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qinputcontext/tst_qinputcontext.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/qinputcontext/tst_qinputcontext.cpp b/tests/auto/qinputcontext/tst_qinputcontext.cpp index 50f9140..644b463 100644 --- a/tests/auto/qinputcontext/tst_qinputcontext.cpp +++ b/tests/auto/qinputcontext/tst_qinputcontext.cpp @@ -68,6 +68,7 @@ private slots: void requestSoftwareInputPanel(); void closeSoftwareInputPanel(); void selections(); + void focusProxy(); }; void tst_QInputContext::maximumTextLength() @@ -248,5 +249,41 @@ void tst_QInputContext::selections() QCOMPARE(le.inputMethodQuery(Qt::ImAnchorPosition).toInt(), 5); } +void tst_QInputContext::focusProxy() +{ + QWidget toplevel(0, Qt::X11BypassWindowManagerHint); toplevel.setObjectName("toplevel"); + QWidget w(&toplevel); w.setObjectName("w"); + QWidget proxy(&w); proxy.setObjectName("proxy"); + QWidget proxy2(&w); proxy2.setObjectName("proxy2"); + w.setFocusProxy(&proxy); + w.setAttribute(Qt::WA_InputMethodEnabled); + toplevel.show(); + QApplication::setActiveWindow(&toplevel); + QTest::qWaitForWindowShown(&toplevel); + w.setFocus(); + w.setAttribute(Qt::WA_NativeWindow); // we shouldn't crash! + + proxy.setAttribute(Qt::WA_InputMethodEnabled); + proxy2.setAttribute(Qt::WA_InputMethodEnabled); + + proxy2.setFocus(); + w.setFocus(); + + QInputContext *gic = qApp->inputContext(); + QVERIFY(gic); + qDebug() << gic->focusWidget() << &proxy; + QCOMPARE(gic->focusWidget(), &proxy); + + // then change the focus proxy and check that input context is valid + QVERIFY(w.hasFocus()); + QVERIFY(proxy.hasFocus()); + QVERIFY(!proxy2.hasFocus()); + w.setFocusProxy(&proxy2); + QVERIFY(!w.hasFocus()); + QVERIFY(proxy.hasFocus()); + QVERIFY(!proxy2.hasFocus()); + QCOMPARE(gic->focusWidget(), &proxy); +} + QTEST_MAIN(tst_QInputContext) #include "tst_qinputcontext.moc" |