Re: [Php-qt-users] QLineEdit and utf-8 strings - unicode support
Status: Beta
Brought to you by:
tm243
From: Ferenc V. <li...@ne...> - 2006-01-17 01:12:34
|
Hi, Thomas Moenicke wrote: >=20 >>QString ( const char * str ) <- looks to be this one now >=20 > Exactly. And=20 > QString ( QChar ch ) > works too. But remember that a char is a number,"a" is a string instead= . So=20 > you have to use use > $mystring =3D new QString(65); I tried that with 337, but that also returned a normal ASCII char. :-) 337 -> Q 338 -> R 0x337 -> 7 So these are not unicode code points. Mabye just mod-128 ASCII values. Actually: QChar () QChar ( char ch ) <-- this is implemented seeing the tests. QChar ( uchar ch ) QChar ( QLatin1Char ch ) QChar ( uchar cell, uchar row ) QChar ( ushort code ) QChar ( short code ) QChar ( uint code ) QChar ( int code ) QChar ( SpecialCharacter ch ) Half of those works with ASCII code, other half unicode code points. :-) > Normally it is possible to provide all constructors, but the others are= still=20 > broken in the current version. Next time I will fire up an improved kal= yptus=20 > script again to solve it. That's great! >>So it looks like the string is just travelling in binary format. (?) >=20 >=20 > The string is stored in the QString object. The zend engine passes it f= rom=20 > your code to the object. In your tests you have proven that it works. Then what is the input encoding? If UTF-8 input just works? Ok, I try with ISO-8859-1. $QString =3D new QString("hell=C3=B3"); written in Latin1 prints broken characters to the output. So is the input encoding UTF-8 for "char*"? I just don't get it. Ok, so UTF-8 is the default input encoding for "char*". Is that right? My test is proves of nothing. See: I input Latin1 chars and output to UTF-8 terminal. I got broken characters. So this may still mean, that "string travels as binary entity", or that "wrong input returns wrong output". While entering UTF-8 text looked fine, that proves either "string travels as binary entity" or "correct input printed correct output". The only proof is when these letters are correctly displayed on the GUI! (As far as I see now.) >>$text =3D QString::fromUtf8($my_database_fetched_variable); // static m= . >>$myLineEdit->setText($text); // (Passing QString there drops core.) >=20 >=20 > The fromUtf8 function does not work for me, I got segfaults. Yes, sorry, that was only a quetion if that would be the right method or not. I mean later. > What is with this piece of code: > $text =3D new QString($my_database_fetched_variable); > $myLineEdit->setText($text); Segfault. :-/ > Note, what we are doing is experimental and the php guys are working on= the=20 > same problems with other tools. I read some of Andrei's implementations= in=20 > php6 and they implemented a function which copies unicode strings to no= rmal=20 > php strings. For php_qt this should be done by Qt's QString::toAscii(),= I=20 > passed the resulting bytearray to a string directly. Yes, I am glad to see that Qt has so advanced features for handling encodings. Note, that "toAscii()" will probably lose some characters, e.g. in Japanese it will lose most of them. :-) I hope that won't be a requirement. Ferenc |