Qt 应用程序的实时搜索不适用于华为 P8 Lite
Qt application's live search not working on Huawei P8 Lite
我正在 Qt Creator 上制作移动应用程序。该应用程序包括搜索本地存储数据库的实时搜索。
我在三星设备上试用了该应用程序,效果很好,但实时搜索在我的华为 8 Lite 上不起作用。
每次 qml TextField 获得焦点时,错误日志中都会出现此错误:
I HwSecImmHelper: mSecurityInputMethodService is null
当我在 TextField 上键入时,没有出现搜索结果。
编辑:
这是该应用程序的简化版本:
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)
};
}
我找到了解决方案。我将 TextField
的 属性 更改信号处理程序从 onTextChanged
更改为 onDisplayTextChanged
并将 text
属性 更改为 displayText
:
onDisplayTextChanged: {
if (search.displayText.length > 0) {
Data.showSearch(search.displayText)
} else {
model.clear()
}
}
实时搜索在我的华为设备上运行,虽然我仍然 I HwSecImmHelper: mSecurityInputMethodService is null
在 TextField
焦点上,但似乎与搜索问题无关。
我正在 Qt Creator 上制作移动应用程序。该应用程序包括搜索本地存储数据库的实时搜索。 我在三星设备上试用了该应用程序,效果很好,但实时搜索在我的华为 8 Lite 上不起作用。 每次 qml TextField 获得焦点时,错误日志中都会出现此错误:
I HwSecImmHelper: mSecurityInputMethodService is null
当我在 TextField 上键入时,没有出现搜索结果。
编辑:
这是该应用程序的简化版本:
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)
};
}
我找到了解决方案。我将 TextField
的 属性 更改信号处理程序从 onTextChanged
更改为 onDisplayTextChanged
并将 text
属性 更改为 displayText
:
onDisplayTextChanged: {
if (search.displayText.length > 0) {
Data.showSearch(search.displayText)
} else {
model.clear()
}
}
实时搜索在我的华为设备上运行,虽然我仍然 I HwSecImmHelper: mSecurityInputMethodService is null
在 TextField
焦点上,但似乎与搜索问题无关。