TextField text field doesn't return value on QML | QT 5.12

寵の児 提交于 2020-01-16 04:50:29

问题


i need an help. So this is my code:

TextField {
    id: passwordIDText
    placeholderText: "Insert text..."
    color: "Black"
    font.bold: true
    font.pixelSize: 21
    anchors.top: parent.top
    anchors.topMargin: parent.height / 10
    anchors.horizontalCenter: parent.horizontalCenter
    text: "aaa"
}

I use Android 8 (P20), QT 12.4, Android NDK 20 and Android SDK 28. So when i click the button on the android screen (i'm using 20 to testing), in debug, for get the passwordIDText.text, the field is empty, why ?? But if i set text: "aaa" hard coded, i get passwordIDText.text = "aaa".

The problem look TextField don't get the value inserted by the user. I've inserted 123456 on TextField on screen and click on Button:

MouseArea {
    anchors.fill: parent
    onClicked: {
        var test = passwordIDText.text;
        //passwordIDText.text is empty wtf !??

    }
}

So someone have the same problem ? On the older Android version TextField works correctly.

My configuration:


回答1:


I believe it might be an issue similar to this question, related to predictive text not being committed at the time you need to access it.

Try using passwordIDText.displayText instead of passwordIDText.text.

Alternatively you can turn down predictive text input:

inputMethodHints: Qt.ImhNoPredictiveText



来源:https://stackoverflow.com/questions/56649760/textfield-text-field-doesnt-return-value-on-qml-qt-5-12

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!