Mr. Developer
Mr. Developer

Reputation: 3417

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

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:

enter image description here

Upvotes: 3

Views: 970

Answers (4)

acdc
acdc

Reputation: 1

I used:

Button{
...
   onClicked:{
       focus = true
       console.log(textarea.text)
   }
...

}

TextArea{
    id: textarea
}

Then the Text is really reachable under textarea.text

hope it helps!

Upvotes: 0

BrutalWizard
BrutalWizard

Reputation: 532

Another way, if you don't want to disable user dictionary or word prediction you should use deselect every time before getting text.

Upvotes: 0

Musa
Musa

Reputation: 514

'ImhNoPredictiveText' didn't solve my problem in Qt 5.14. so i used

inputMethodHints: Qt.ImhSensitiveData

and it worked great.

Upvotes: 1

augre
augre

Reputation: 2051

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

Upvotes: 3

Related Questions