Qt应用程序的实时搜索在华为P8 Lite上不起作用



我正在Qt Creator上制作一个移动应用程序。该应用程序包括搜索本地存储数据库的实时搜索。 我在三星设备上尝试了该应用程序,效果很好,但是实时搜索在我的华为8 Lite上不起作用。 每次 qml 文本字段获得焦点时,错误日志中都会出现此错误:

I HwSecImmHelper: mSecurityInputMethodService is null

当我在文本字段上键入时,没有出现搜索结果。

编辑:

以下是该应用程序的简化版本:

主.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焦点,但似乎与搜索问题无关。

相关内容

  • 没有找到相关文章

最新更新