How to get Intput from TextInput upon pressing the done button on Android keyborad.[solved]
-
I have textinput which accepts only integers but only works only on windows. Not working on Android, it is accepting strings also. Now I want send data to C++ upon textChanged.I tried with onTextChanged but it is emitting for every letter a type. I want to send only after whole text is completed. So I tried with onActiveFocusChanged but it is emitted when ever focus get activated which doesnot serve my purpose.So i thought upon pressing the Done button on Android keyboard sending the input to c++ side. How to do that? or is there any other signal handler or logic which serves my purpose: Sending the text to backend only upon text changed and whole value is written.
UnitBox.qmlproperty DoubleValidator inputvalidate property alias value: input.text Rectangle{ id: inputrec width: parent.width/2 height: parent.height border.width: 2 border.color: "black" TextInput{ id: input validator: inputvalidate focus: false clip: true anchors.fill: parent font.pixelSize: festoDesign.fontSizeLarge horizontalAlignment: Text.AlignHCenter anchors.horizontalCenter: inputrec.horizontalCenter anchors.verticalCenter: inputrec.verticalCenter onActiveFocusChanged: { console.log(value) } } }
controlView.qml
UnitBox{ id:override unit: "%" inputvalidate: DoubleValidator{bottom: 1;top: 100;decimals: 0}// not working on Android anchors.left: parent.left anchors.leftMargin: festodesign.spacingBetweenLabelandStausRegisters anchors.top: joggingModeRegisterStatus.bottom anchors.topMargin: festodesign.spacingBetweenStatusRegister border.width: 1 border.color: "black" height: festodesign.statusRegisterHeight width: festodesign.statusRegisterWidth //what is the signal handler ? } UnitBox{ id:targetPosX unit: "mm" inputvalidate: DoubleValidator{bottom: -1500;top: 1500;decimals: 1000}// not working on Android anchors.left: parent.left anchors.leftMargin: festodesign.spacingBetweenLabelandStausRegisters anchors.top: override.bottom anchors.topMargin: festodesign.spacingBetweenStatusRegister border.width: 1 border.color: "black" height: festodesign.statusRegisterHeight width: festodesign.statusRegisterWidth //what is the signal handler ? }
Please help me.Thanks a lot.
-
@vishnucool220 Use accepted or editingFinished signal. Add their respective signal handlers. It will be triggered when enter/return key is pressed.
-
@p3c0
Perfect. You're awesome buddy. you will be first one here to answer my quesitons.Thanks a lot. But why the Textinput is accepting the characters even though i kept doubleValidator? -
@vishnucool220 Thank You :)
Well does it work on desktop ? -
@vishnucool220 It works on android too. You are seeing them because it is still in composing state. Once you click enter it should be gone.
To avoid this also you can setinputMethodHints: Qt.ImhDigitsOnly
orinputMethodHints: Qt.ImhNoPredictiveText
(this disables the dictionary support) -
@p3c0
yes. But code works perfect it is sending the data which is in the limit. If i put a value which is not validated it is not sending.No problem at the backend . Only problem is for the user. The user might think it is valid number.How can i restrict him not to give invalid input? Thanks -
@vishnucool220 Did you try setting
inputMethodHints
as said earlier ? -
@p3c0
inputMethodHints: Qt.ImhDigitsOnly work perfect. Now i accepts only digits. But the user can give me than the range specified in the validator. not working both on windows and android. -
@vishnucool220 And what is that range ?
-
@p3c0
inputvalidate: DoubleValidator{bottom: -1500;top: 1500;decimals: 1000} -
@vishnu try changing notation property to StandardNotation
-
@p3c0
perfect but the problem is it accepting till 4 digits. i.e Even though my top value :1500 .user can put till 9999.Any solution ? -
@vishnu Hmm that is expected behavior. From the docs:
Input is accepected but invalid if it contains a double that is outside the range or is in the wrong format; e.g. with too many digits after the decimal point or is empty.
In this case use the
accepted
signal to check the validity of the input. It won't trigger if the number is not in that range.TextInput{ validator: DoubleValidator { bottom: -1500; top: 1500; decimals: 1000; notation: DoubleValidator.StandardNotation } onAccepted: console.log("Accepted") //won't trigger if not input not valid }
-
@p3c0
Perfect. Instead on poping up new thread .I want to ask here itself. when ever i press on the TextInput Box on Android . These were shown on the application output. What does it mean ? Is something wrong ?
W/IInputConnectionWrapper( 7920): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7920): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7920): showStatusIcon on inactive InputConnection
W/IInputConnectionWrapper( 7920): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7920): endBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7920): beginBatchEdit on inactive InputConnection
W/IInputConnectionWrapper( 7920): endBatchEdit on inactive InputConnection -
@vishnu No. I guess they are debug messages from functions in android's apis.
-
@p3c0
Okay.