02-27-2013 04:44 PM
I need to set a max length for a TextField.
It seems there's no any property that does this.
Any idea about this?
Solved! Go to Solution.
02-27-2013 04:47 PM - edited 02-27-2013 04:47 PM
The first approach which comes to mind is trimming the string to required length in onTextChanging handler.
if (id.text.length > 30) id.text = id.text.substr(0,30);
02-27-2013 07:12 PM
But for some kind of languages, because one character has two bytes, it also has the possibility that the result is over the expect length of bytes. We should be aware of this case.
02-27-2013 07:24 PM
02-27-2013 07:47 PM - edited 02-27-2013 07:51 PM
Yes. It is what I worry about. Such as there is one length restrain in one DB field say 20 bytes, if one text has 20 characters but it maybe has 40 bytes. Although it can pass the length check for characters at the client side, when it is inserted into that DB field, it will cause an error.
I just extend this topic. lol
01-24-2014 11:28 AM - edited 01-24-2014 11:28 AM
You can easily set the maximum TextField length by the method :
Q_SLOT void setMaximumLength(int maximumLength)
available from API 10.2