Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to get Intput from TextInput upon pressing the done button on Android keyborad.[solved]
Forum Updated to NodeBB v4.3 + New Features

How to get Intput from TextInput upon pressing the done button on Android keyborad.[solved]

Scheduled Pinned Locked Moved QML and Qt Quick
16 Posts 2 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • vishnuV Offline
    vishnuV Offline
    vishnu
    wrote on last edited by vishnu
    #1

    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.qml

    property 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.

    p3c0P 1 Reply Last reply
    0
    • vishnuV vishnu

      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.qml

      property 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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @vishnucool220 Use accepted or editingFinished signal. Add their respective signal handlers. It will be triggered when enter/return key is pressed.

      157

      vishnuV 1 Reply Last reply
      1
      • p3c0P p3c0

        @vishnucool220 Use accepted or editingFinished signal. Add their respective signal handlers. It will be triggered when enter/return key is pressed.

        vishnuV Offline
        vishnuV Offline
        vishnu
        wrote on last edited by vishnu
        #3

        @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?

        p3c0P 2 Replies Last reply
        0
        • vishnuV vishnu

          @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?

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @vishnucool220 Thank You :)
          Well does it work on desktop ?

          157

          vishnuV 1 Reply Last reply
          0
          • vishnuV vishnu

            @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?

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @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 set inputMethodHints: Qt.ImhDigitsOnly or inputMethodHints: Qt.ImhNoPredictiveText(this disables the dictionary support)

            157

            1 Reply Last reply
            1
            • p3c0P p3c0

              @vishnucool220 Thank You :)
              Well does it work on desktop ?

              vishnuV Offline
              vishnuV Offline
              vishnu
              wrote on last edited by
              #6

              @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

              p3c0P 1 Reply Last reply
              0
              • vishnuV vishnu

                @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

                p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                @vishnucool220 Did you try setting inputMethodHints as said earlier ?

                157

                vishnuV 1 Reply Last reply
                0
                • p3c0P p3c0

                  @vishnucool220 Did you try setting inputMethodHints as said earlier ?

                  vishnuV Offline
                  vishnuV Offline
                  vishnu
                  wrote on last edited by
                  #8

                  @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.

                  p3c0P 1 Reply Last reply
                  0
                  • vishnuV vishnu

                    @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.

                    p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #9

                    @vishnucool220 And what is that range ?

                    157

                    vishnuV 1 Reply Last reply
                    0
                    • p3c0P p3c0

                      @vishnucool220 And what is that range ?

                      vishnuV Offline
                      vishnuV Offline
                      vishnu
                      wrote on last edited by
                      #10

                      @p3c0
                      inputvalidate: DoubleValidator{bottom: -1500;top: 1500;decimals: 1000}

                      p3c0P 1 Reply Last reply
                      0
                      • vishnuV vishnu

                        @p3c0
                        inputvalidate: DoubleValidator{bottom: -1500;top: 1500;decimals: 1000}

                        p3c0P Offline
                        p3c0P Offline
                        p3c0
                        Moderators
                        wrote on last edited by
                        #11

                        @vishnu try changing notation property to StandardNotation

                        157

                        vishnuV 1 Reply Last reply
                        0
                        • p3c0P p3c0

                          @vishnu try changing notation property to StandardNotation

                          vishnuV Offline
                          vishnuV Offline
                          vishnu
                          wrote on last edited by
                          #12

                          @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 ?

                          p3c0P 1 Reply Last reply
                          0
                          • vishnuV vishnu

                            @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 ?

                            p3c0P Offline
                            p3c0P Offline
                            p3c0
                            Moderators
                            wrote on last edited by
                            #13

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

                            157

                            vishnuV 1 Reply Last reply
                            1
                            • p3c0P p3c0

                              @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
                              }
                              
                              vishnuV Offline
                              vishnuV Offline
                              vishnu
                              wrote on last edited by
                              #14

                              @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

                              p3c0P 1 Reply Last reply
                              0
                              • vishnuV vishnu

                                @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

                                p3c0P Offline
                                p3c0P Offline
                                p3c0
                                Moderators
                                wrote on last edited by
                                #15

                                @vishnu No. I guess they are debug messages from functions in android's apis.

                                157

                                vishnuV 1 Reply Last reply
                                0
                                • p3c0P p3c0

                                  @vishnu No. I guess they are debug messages from functions in android's apis.

                                  vishnuV Offline
                                  vishnuV Offline
                                  vishnu
                                  wrote on last edited by
                                  #16

                                  @p3c0
                                  Okay.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved