Results 1 to 13 of 13

Thread: setting regExpValidator for TextInput in QMl is not working

  1. #1
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default setting regExpValidator for TextInput in QMl is not working

    HI,
    I just want to set a hexadecimal validator for my TextInput field in the qml, but somehow it is not validating. Instead of regExpValidator if i use intValidator it works. but I need to have a hexadecimal validator. again if i use Inputmask , it works but I need to specify the no of characters which I cant becuase I need to have it as unlimited.
    here is the code sample:
    javascript Code:
    1. TextInput{
    2. id:display
    3. text:some value from cpp
    4. font.pixelSize: 16
    5. width:parent.width-30
    6. focus:true
    7. font.bold: true
    8. validator: RegExpValidator{regExp: /[0-9A-F]/} // not at all validated
    9. inputMask: ">HHHHHH" // input mask limited for the 6 characters
    10. anchors.fill:parent.Center
    11. anchors {
    12. left: parent.left;
    13. verticalCenter: parent.verticalCenter;
    14. verticalCenterOffset: -1
    15. leftMargin: 5;
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 
    please help if any body has any idea.
    Thanks in advance
    Last edited by wysota; 1st August 2013 at 12:13. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting regExpValidator for TextInput in QMl is not working

    It seems your regular expression only allows a single digit. Try /[0-9A-F]+/ instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    Hi wysota,
    thanks for your reply, but validation is not at all happening.
    not for a single digit too. other validators are working fine. I am displaying the default text inside my TextInput and this is also getting validated before displaying when i use some other validators like intvalidator but in case of regExpValidator, it's not doing any kind of validation.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting regExpValidator for TextInput in QMl is not working

    Quote Originally Posted by RJ View Post
    Hi wysota,
    thanks for your reply, but validation is not at all happening.
    not for a single digit too. other validators are working fine.
    This works fine for me:
    javascript Code:
    1. import QtQuick 2.0
    2.  
    3. Rectangle {
    4. width: 600
    5. height: 300
    6.  
    7. TextInput {
    8. focus: true
    9. anchors.fill: parent
    10. validator: RegExpValidator { regExp: /[0-9A-F]+/ }
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    thanks....its working fine
    but the problem is I am setting the text property with some older value which is not a valid input, then this should not display that but it is displaying. do you have any idea why?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting regExpValidator for TextInput in QMl is not working

    Quote Originally Posted by RJ View Post
    but the problem is I am setting the text property with some older value which is not a valid input, then this should not display that but it is displaying. do you have any idea why?
    Validator works on user input, not on a text set programatically.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    ok thanks wysota

  8. #8
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    i have one more problem with this Validator.
    I want to change the validator regular exp by using state change. its able to set the other properties based on the states but not validator.
    javascript Code:
    1. TextInput
    2. {
    3. id:qVirtualKeyboardTextInput
    4. validator: RegExpValidator { regExp: /[0-9A-Fa-f.-]+/ }
    5. text:EditText
    6. }
    7. states:[
    8. State
    9. {
    10. name:binaryvalidator
    11. when: binaryIOField ==true && decimalIOField=== false
    12. PropertyChanges {
    13. target: TextInput;
    14. validator: IntValidator{bottom:0; top:1} // not working , tried with regExp alsio :(
    15. }
    16.  
    17. },
    18. State
    19. {
    20. name:decimalvalidator === true
    21. when: decimalIOField
    22. PropertyChanges {
    23. target: TextInput;
    24. //validator: IntValidator{bottom:0; top:9}
    25. inputMask:"9" // able to set the input mask but not validator
    26. }
    27.  
    28. }
    29. ]
    To copy to clipboard, switch view to plain text mode 
    can any body tell me why it is not taking. i am getting the error that "component is not ready"
    Last edited by wysota; 7th August 2013 at 14:30.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting regExpValidator for TextInput in QMl is not working

    Define all validators you need and only switch which is currently used.

    javascript Code:
    1. ... {
    2. IntValidator { id: intValidator; ... }
    3. RegExpValidator { id: regexpValidator; ... }
    4.  
    5. TextInput {
    6. validator: useIntValidator ? intValidator : regexpValidator // you can do the same with PropertyChanges
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    hi,
    thanks for the reply..I think , I need to use PropertyChanges only because I have more than 3 conditions and I can not use ternary operator for that. Let me try, if it works for me or not.

  11. #11
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    hi wysota,
    its working fine with the propertychanges also. only one issue is there. by default my textinput has selected value(displaying it in a highlighted mode). so for the first time input it doesn't go for the validation. If I use the backspace to empty the input field and then if try to give some value to the input field , it goes for the validation and works perfectly. why is it so? any idea?
    Thanks in advance

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: setting regExpValidator for TextInput in QMl is not working

    I have already told you -- the validator only work on user input, not on content that is already set in the item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Aug 2012
    Posts
    29
    Thanked 2 Times in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: setting regExpValidator for TextInput in QMl is not working

    its working fine
    this problem comes only when you have wrong invalidated input value in your input field. I f you have the correctly validated value then it doesn't allow the wrong inputs. Thanks a lot
    makin it as a Solved thread now.
    Quote Originally Posted by RJ View Post
    hi wysota,
    its working fine with the propertychanges also. only one issue is there. by default my textinput has selected value(displaying it in a highlighted mode). so for the first time input it doesn't go for the validation. If I use the backspace to empty the input field and then if try to give some value to the input field , it goes for the validation and works perfectly. why is it so? any idea?
    Thanks in advance

Similar Threads

  1. TextInput overflow
    By Viper666 in forum Qt Quick
    Replies: 2
    Last Post: 2nd January 2013, 13:52
  2. QtSocks5 setting not working
    By psridharan in forum Qt Programming
    Replies: 0
    Last Post: 17th December 2012, 21:24
  3. Replies: 7
    Last Post: 24th September 2012, 08:17
  4. setting working directory for current process
    By mule in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2007, 14:54
  5. help setting up qt4 ui from qt3
    By illuzioner in forum Qt Programming
    Replies: 3
    Last Post: 24th June 2007, 05:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.