How to make QML TextField binding work under Android?

别说谁变了你拦得住时间么 提交于 2019-12-01 23:21:48

As far as I understand the comments to my question, I have a few possibilities to solve this problem. The simplest one is to modify my QML item like this:

ColumnLayout {
  TextField {
    id: myField
    placeholderText: qsTr("Enter text")
    Layout.fillWidth: true
    Binding {
      target: myClass
      property: "prop"
      value: myField.displayText
    }
}

If I didn't want to allow predictive text input, then I could just add the

inputMethodHints: Qt.ImhNoPredictiveText

on the TextField. In my case, I want predictive text input.

Last, I could call QInputMethod::commit() when I click the button "Done" of my application, which will commit the displayed text on Android and then use the committed text in MyClass. In this case, I should not use QML's Binding feature. Instead, I should just commit the data to Android and then communicate my QML data to myClass.

The simplest solution that best fits QML philosophy is probably to use displayText instead of text, which is the solution I am choosing.

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