Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Textfield validator probelm

Textfield validator probelm

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 3 Posters 2.2k Views
  • 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.
  • E Offline
    E Offline
    eswar
    wrote on 1 Feb 2018, 11:27 last edited by
    #1

    Hi

    I created a textfield and assign the text to the field. In that , the validator not validate the text properly. how can i validate the text.

    code snippet:

    TextField{
        id:pt
        z:5
        x: 278
        y: 43
        text: ""
        width: 200
        height: 38
       validator: IntValidator {bottom: 000; top: 999;}
    
        Component.onCompleted:
        {
              pt.text="hi"
        }
    }
    

    In that above code, integer validator was used in the textfield and i will pass the string to the textfield. It display the string without validation. If i enter the string in the textfield, i validate perfectly. How can i solve the problem?

    J 1 Reply Last reply 1 Feb 2018, 12:19
    0
    • E eswar
      1 Feb 2018, 11:27

      Hi

      I created a textfield and assign the text to the field. In that , the validator not validate the text properly. how can i validate the text.

      code snippet:

      TextField{
          id:pt
          z:5
          x: 278
          y: 43
          text: ""
          width: 200
          height: 38
         validator: IntValidator {bottom: 000; top: 999;}
      
          Component.onCompleted:
          {
                pt.text="hi"
          }
      }
      

      In that above code, integer validator was used in the textfield and i will pass the string to the textfield. It display the string without validation. If i enter the string in the textfield, i validate perfectly. How can i solve the problem?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 1 Feb 2018, 12:19 last edited by
      #2

      @eswar I'm not a QML expert but I guess these validators are used for user input.
      Why do you try to set values which shouldn't be accepted in your code?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Pablo J. Rogina
        wrote on 1 Feb 2018, 19:50 last edited by
        #3

        @eswar I tried your code and it might be considered a bug, although as @jsulm pointed out, validators are expected to work on user input, which it does. Not sure why you will set an inappropriate value programmatically. Anyway, a workaround could be working on the onTextChanged signal, to see if the current value is indeed acceptable:

        TextField{
            id:pt
            ...
            validator: IntValidator {bottom: 000; top: 999;}
            onTextChanged: 
                if (!pt.acceptableInput) {
                    console.log("unacceptable input, changed to default value");
                    text = 0
                }
            Component.onCompleted:
            {
             ...
        

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • E Offline
          E Offline
          eswar
          wrote on 2 Feb 2018, 07:24 last edited by
          #4

          Hi @jsulm & @Pablo-J-Rogina

          Thanks for you comment

          My requirement is like to get text input from user as well as update the text based on the some external factors in the textfield. so that, i tested the textfield with different data. so that, i found that the validator allows the inappropriate data to the textfield. It didn't satisfy my requirements. In my project, all the textfield similar to the above requirements.

          Any other solution to solve this issue?

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pablo J. Rogina
            wrote on 2 Feb 2018, 11:03 last edited by
            #5

            @eswar with due respect, have you looked at the code snippet I posted? You may want to check if the value set to the textfield is acceptable, whenever the value was entered by the user or programmatically, and if value is not acceptable, set some default value. I guess that's an appropriate workaround along with using validators

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            E 1 Reply Last reply 6 Feb 2018, 05:48
            1
            • P Pablo J. Rogina
              2 Feb 2018, 11:03

              @eswar with due respect, have you looked at the code snippet I posted? You may want to check if the value set to the textfield is acceptable, whenever the value was entered by the user or programmatically, and if value is not acceptable, set some default value. I guess that's an appropriate workaround along with using validators

              E Offline
              E Offline
              eswar
              wrote on 6 Feb 2018, 05:48 last edited by
              #6

              @Pablo-J.-Rogina

              Hi

              Its working fine.. Thanks for the solution..

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pablo J. Rogina
                wrote on 6 Feb 2018, 15:09 last edited by
                #7

                @eswar great! so if your problem is solved, please use the Topic Tools button to mark as Solved and upvote the answer(s) that helped you to solve the issue. Thank you.

                Upvote the answer(s) that helped you solve the issue
                Use "Topic Tools" button to mark your post as Solved
                Add screenshots via postimage.org
                Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                1

                1/7

                1 Feb 2018, 11:27

                • Login

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