Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, July 2007
QLineEdit::setMaxLength() not working with japanese characters


Message 1 in thread

Hi All,
I have a QLineEdit in my application in which I should be able to enter
a maximum of 10byte characters in english and while entering Japanese
characters , if the character is of 2byte , I should be able to enter
only 5 characters in japanese and if the Japanese character is a 1byte
character, I should be able to enter 10 characters in japanese. Please
help me with this.

I tried using QLineEdit::setMaxLength(10) but it is working fine only
with English characters but now with Japanese characters.
Regards
Naveen


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
 
www.wipro.com

--
 [ signature omitted ] 

Message 2 in thread

naveen.kmrvm@xxxxxxxxx wrote:
> Hi All,
> I have a QLineEdit in my application in which I should be able to enter
> a maximum of 10byte characters in english and while entering Japanese
> characters , if the character is of 2byte , I should be able to enter
> only 5 characters in japanese and if the Japanese character is a 1byte
> character, I should be able to enter 10 characters in japanese. Please
> help me with this.
> 
> I tried using QLineEdit::setMaxLength(10) but it is working fine only
> with English characters but [not] with Japanese characters.

... in that it's permitting 10 Japanese characters too?

That's by design. Qt uses Unicode strings internally. It does not expose
the "size" in bytes of a character to the user except through encoding
conversion APIs. The character 'a' and the character 'ã' are, to Qt,
not all that different, in that they're both representable by QChar and
by a single character in a QString.

Consequently you must treat this as a normal data verification task.
There is PLENTY of information on how to set up verification (both
as-you-type and on submit) for Qt input controls.

Your verification will probably want to look at the length of the input
string when encoded to a particular 8-bit encoding. However, if your
application is particularly weird you might scan the string and look at
each QChar instead.

> The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 
> 
> WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
>  
> www.wipro.com

Please get rid of this crud when posting to a mailing list.

--
 [ signature omitted ]