PDA

View Full Version : Display more than four digits/characters



StarRocks
28th January 2013, 06:59
Dear Forums,


Im a newbie in QT.....I have a doubt regarding QlineEdit actually i need to have max of 10numbers if i enter 5 numbers it should raise me an error saying please enter max of 10 numbers........I have restricted to 10 that i have done but not knowing how to restrict the one i have asked for........Thanks in Advance.........


Regards,

ChrisW67
28th January 2013, 23:56
Your requirement is not consistent, so perhaps you should attend to that first. You want at most 10 digits and say that 5 digits is not acceptable with a message indicating the user should enter a maximum of 10 digits. As far as the user is concerned, they have entered a maximum of 10, that is than or equal to 10 digits.

You can use an input mask or QValidator or one if its subclasses to restrict what is acceptable input for a QLineEdit.

wysota
29th January 2013, 00:25
Maybe it's "10" in binary ;)

StarRocks
29th January 2013, 04:29
Dear Chris,

Thanks for the reply......I want a validation in the button event so that when i click the button it should raise me an error saying please enter the field greater than four digits/characters......Any reply would be appreciable.......Thanks in Advance.......

Regards,

lanz
29th January 2013, 06:08
So you should do as you said, it's not rocket science .)

In your button event handler check lineEdit->text ().length () > 4.
Don't forget to exclude/replace spaces if needed and if you haven't filtered them in input mask.

ChrisW67
29th January 2013, 22:23
Thanks for the reply......I want a validation in the button event so that when i click the button it should raise me an error saying please enter the field greater than four digits/characters......Any reply would be appreciable.......Thanks in Advance.......

And I want a pony... but I have to work for the horse feed. Show the code you have used to try to do these size checks when a button is clicked.

BTW, your requirements are now:

Maximum of 10 characters (from first post)
More than 4 characters (from second post)
But not 5 characters ??? (from first post)


Also consider that another solution may be to stop the user from clicking the button unless their input is already valid.

StarRocks
31st January 2013, 08:45
Dear Lanz,


Thanks for the reply.......Its working fine for me when i give in the button event but a small correction in the syntax



its not
lineEdit->text ().length () > 4
rather its
lineEdit->text ().length () < 4



thats the only difference.......Thanks in Advance.....Hope i guess thats the better way to code......Any ideas would be appreciable.....


Regards,

ChrisW67
31st January 2013, 09:19
So now 4 characters is acceptable. :confused:

StarRocks
2nd February 2013, 09:12
Dear Chris,


Thanks for the reply......It Really worked fine for me............Thanks in Advance


Regards,