I'm making a mobile application on Qt Creator. The app includes live search which searches the Local Storage database. I tried the app on Samsung devices and it works great, but the live search is not working on my Huawei 8 Lite. Every time the qml TextField gains focus this error appears on the error log:
I HwSecImmHelper: mSecurityInputMethodService is null
While I type on the TextField no search result appears.
Edit:
Here is a simplified version of the app:
main.qml
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import QtQuick.LocalStorage 2.0
import "js/Data.js" as Data
ApplicationWindow {
id: window
visible: true
width: 360
height: 480
header: ToolBar {
width: parent.width
RowLayout {
width: parent.width
TextField {
id: search
Layout.fillWidth: true
placeholderText: "Search..."
onTextChanged: {
if (search.text.length > 0) {
Data.showSearch(search.text)
} else {
model.clear()
}
}
}
ToolButton {
icon.source: "icons/close.svg"
onClicked: {
search.text = ""
search.focus = true
}
}
}
} // Header ends
ListView {
anchors.fill: parent
model: ListModel {
id: model
}
delegate: Row {
width: parent.width
Text {
text: number
}
Text {
text: title
}
}
}
Component.onCompleted: Data.init()
}
js/Data.js
function showSearch(searchedText) {
var db = LocalStorage.openDatabaseSync("test_db", "", "", 1000000)
db.transaction(function (tx) {
var results = tx.executeSql('SELECT * FROM test')
var i, haystack, needle = searchedText.toUpperCase()
model.clear()
for (i = 0; i < results.rows.length; i++) {
haystack = results.rows.item(i).title.toUpperCase()
if (haystack.indexOf(needle) > -1) {
model.append({
number: results.rows.item(i).number,
title: results.rows.item(i).title,
star: results.rows.item(i).star
})
}
}
})
}
function init() {
var db = LocalStorage.openDatabaseSync("test_db", "", "", 1000000)
try {
db.transaction(function (tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS test (number INTEGER, title TEXT, star INTEGER)');
var r = tx.executeSql('SELECT * FROM test');
if (r.rows.length === 0) {
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [1, 'First', false]);
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [2, 'Second', false]);
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [3, 'Third', false]);
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [4, 'Fourth', false]);
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [5, 'Fifth', false]);
tx.executeSql('INSERT INTO test VALUES (?, ?, ?)', [99, 'Ninety-ninth', false]);
}
})
} catch (err) {
console.log("Error creating table in database: " + err)
};
}
I found the solution. I changed the property change signal handler of the TextField
from onTextChanged
to onDisplayTextChanged
and text
property to displayText
:
onDisplayTextChanged: {
if (search.displayText.length > 0) {
Data.showSearch(search.displayText)
} else {
model.clear()
}
}
The live search is working on my Huawei device, although I'm still getting I HwSecImmHelper: mSecurityInputMethodService is null
on TextField
focus, but it seems that was not related to the search problem.