diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2015-04-10 14:40:32 +0300 |
---|---|---|
committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2015-04-10 15:27:58 +0300 |
commit | ed8a4653103403f21d88e8981cf4464e2628f96c (patch) | |
tree | 564a695a2777e1968f703985de9772fdf014aff8 | |
parent | 80ebe0d1e3061aaf5ba792f21813e0a8804112ad (diff) |
Fix crash if a selection list item is selected while transitioning outv1.3.0-rc1
This crash occurs if the selection list item is selected right after
the selection list is updated in such way that some of the items in
the list are removed and transtioned away. If such item is selected,
the application would crash.
Change-Id: Iff7002932d94c9072044bb159af268cba3aa26ac
Reviewed-by: Rainer Keller <rainer.keller@theqtcompany.com>
4 files changed, 18 insertions, 2 deletions
diff --git a/src/virtualkeyboard/content/components/Keyboard.qml b/src/virtualkeyboard/content/components/Keyboard.qml index c4e28284..a24fee30 100644 --- a/src/virtualkeyboard/content/components/Keyboard.qml +++ b/src/virtualkeyboard/content/components/Keyboard.qml @@ -471,7 +471,7 @@ Item { Connections { target: wordCandidateView.model ? wordCandidateView.model : null onActiveItemChanged: wordCandidateView.currentIndex = index - onItemSelected: soundEffect.play(wordCandidateView.currentItem.soundEffect) + onItemSelected: if (wordCandidateView.currentItem) soundEffect.play(wordCandidateView.currentItem.soundEffect) } Loader { sourceComponent: style.selectionListBackground diff --git a/src/virtualkeyboard/declarativeselectionlistmodel.cpp b/src/virtualkeyboard/declarativeselectionlistmodel.cpp index a124d1c1..de8599e2 100644 --- a/src/virtualkeyboard/declarativeselectionlistmodel.cpp +++ b/src/virtualkeyboard/declarativeselectionlistmodel.cpp @@ -191,7 +191,7 @@ QHash<int,QByteArray> DeclarativeSelectionListModel::roleNames() const void DeclarativeSelectionListModel::selectItem(int index) { Q_D(DeclarativeSelectionListModel); - if (d->dataSource) { + if (index >= 0 && index < d->rowCount && d->dataSource) { emit itemSelected(index); d->dataSource->selectionListItemSelected(d->type, index); } diff --git a/src/virtualkeyboard/styles/SelectionListItem.qml b/src/virtualkeyboard/styles/SelectionListItem.qml index 74447c33..e196d839 100644 --- a/src/virtualkeyboard/styles/SelectionListItem.qml +++ b/src/virtualkeyboard/styles/SelectionListItem.qml @@ -44,6 +44,8 @@ Item { anchors.fill: parent hoverEnabled: true onClicked: { + if (index === -1) + return selectionListItem.ListView.view.currentIndex = index selectionListItem.ListView.view.model.selectItem(index) } diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index 96e820b1..0385e394 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -608,6 +608,20 @@ Rectangle { compare(textInput.text, data.outputText) } + function test_selectionListSelectInvalidItem() { + prepareTest() + + // Note: This test passes if it does not crash + if (inputPanel.wordCandidateView.model) { + compare(inputPanel.wordCandidateView.count, 0) + inputPanel.wordCandidateView.model.selectItem(-2) + inputPanel.wordCandidateView.model.selectItem(-1) + inputPanel.wordCandidateView.model.selectItem(0) + inputPanel.wordCandidateView.model.selectItem(1) + inputPanel.wordCandidateView.model.selectItem(2) + } + } + function test_pinyinInputMethod_data() { return [ { initInputMethodHints: Qt.ImhNone, initLocale: "zh_CN", inputSequence: "suoer", expectedCandidates: [ "\u7D22\u5C14" ], outputText: "\u7D22\u5C14" }, |