【问题标题】:TextField text field doesn't return value on QML | QT 5.12TextField 文本字段在 QML 上不返回值 | QT 5.12
【发布时间】:2019-06-18 12:59:39
【问题描述】:

我需要帮助。 所以这是我的代码:

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"
}

我使用 Android 8 (P20)、QT 12.4、Android NDK 20 和 Android SDK 28。 因此,当我单击 android 屏幕上的按钮(我使用 20 进行测试)时,在调试中,为了获取 passwordIDText.text,该字段为空,为什么?但是如果我设置 text: "aaa" 硬编码,我会得到 passwordIDText.text = "aaa"。

问题看起来 TextField 没有得到用户插入的值。我已在屏幕上的 TextField 上插入 123456 并单击按钮:

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

    }
}

那么有人有同样的问题吗?在较旧的 Android 版本上,TextField 可以正常工作。

我的配置:

【问题讨论】:

    标签: android qt android-ndk qml textfield


    【解决方案1】:

    我认为这可能是类似于this question 的问题,与在您需要访问它时未提交预测文本有关。

    尝试使用passwordIDText.displayText 而不是passwordIDText.text

    或者,您可以关闭预测文本输入:

    inputMethodHints: Qt.ImhNoPredictiveText

    【讨论】:

      【解决方案2】:

      'ImhNoPredictiveText' 没有解决我在 Qt 5.14 中的问题。所以我用了

      inputMethodHints: Qt.ImhSensitiveData
      

      效果很好。

      【讨论】:

        【解决方案3】:

        另一种方式,如果您不想禁用用户词典或单词预测,您应该在每次获取文本之前使用deselect

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-08-16
          • 1970-01-01
          • 2023-03-29
          • 2021-03-20
          • 1970-01-01
          相关资源
          最近更新 更多