Thread: [Php-qt-users] QLineEdit and utf-8 strings
Status: Beta
Brought to you by:
tm243
From: Ferenc V. <li...@ne...> - 2006-01-16 10:11:04
|
Hi all, I've two small questions. 1. QLineEdit->$text (with plain ascii text first) Works: $this->txtGuessPercents[$i]->setText($tr["percent"]."%"); Does not work: $this->txtGuessPercents[$i]->$text = $tr["percent"]."%"; Error message: "Cannot access empty property". According to the Qt docs there is a .text property, but I don't understand the ZEND code in qlineedit.cpp to see what it can do. :-) 2. QString character code conversions I think these routines are not ready yet, it would be great to have them as time allows. As you could saw on my tests, all localized strings were displayed broken. ::toUtf8 ::fromUtf8 and similar functions. I don't have any utf-16 strings, so all I can do with QString is dumping core files. :-) $txt = new QString("Hello"); $this->txtGuessTranslations[$i]->setText($txt); Something like that? (Dumps core at the moment, in the second line.) That would probably require QString's static ::fromUtf8 or ::fromAscii methods, becase "Hello" written in source code is not Unicode. Anyway, I am not sure my code handles the UTF-8 strings right, I did nothing more than adding the encoding to the originating XML's header and creating MySQL tables with UTF-8 setting. I did nothing in PHP direcly. (I don't have such strings in the source code of course.) When I fill those UTF-8 strings to the QLineEdit, they display as "UTF-8 binary". Thanks, Ferenc _______________________________________________ Php-qt-users mailing list Php...@li... http://lists.berlios.de/mailman/listinfo/php-qt-users |
From: Thomas M. <tm...@ip...> - 2006-01-16 11:37:41
|
Ferenc Veres wrote on Montag, 16. Januar 2006 01:41: > Works: > $this->txtGuessPercents[$i]->setText($tr["percent"]."%"); > > Does not work: > $this->txtGuessPercents[$i]->$text = $tr["percent"]."%"; > > Error message: "Cannot access empty property". According to the Qt docs > there is a .text property, but I don't understand the ZEND code in > qlineedit.cpp to see what it can do. :-) This is not possible. PHP-properties are provided as you can see in a few classes. You can readout it, but not write to it directly. It may be possible to store your values into the php object, but property is a passive element and cannot forward its value to the real C++ object. You have to use the setText() way to store the value instead. > 2. QString character code conversions > > I think these routines are not ready yet, it would be great to have them > as time allows. As you could saw on my tests, all localized strings were > displayed broken. > > ::toUtf8 > ::fromUtf8 > > and similar functions. > > I don't have any utf-16 strings, so all I can do with QString is dumping > core files. :-) > > $txt = new QString("Hello"); > $this->txtGuessTranslations[$i]->setText($txt); > > Something like that? (Dumps core at the moment, in the second line.) > That would probably require QString's static ::fromUtf8 or ::fromAscii > methods, becase "Hello" written in source code is not Unicode. > > Anyway, I am not sure my code handles the UTF-8 strings right, I did > nothing more than adding the encoding to the originating XML's header > and creating MySQL tables with UTF-8 setting. I did nothing in PHP > direcly. (I don't have such strings in the source code of course.) > > When I fill those UTF-8 strings to the QLineEdit, they display as "UTF-8 > binary". I write it to the TODO list. It seems to be a little bit tricky, I hope we do not have to touch the zend engine ;-) -- Thomas _______________________________________________ Php-qt-users mailing list Php...@li... http://lists.berlios.de/mailman/listinfo/php-qt-users |
From: Thomas M. <tm...@ip...> - 2006-01-16 17:17:00
|
Ferenc Veres wrote on Montag, 16. Januar 2006 01:41: > 2. QString character code conversions > > I think these routines are not ready yet, it would be great to have them > as time allows. As you could saw on my tests, all localized strings were > displayed broken. > > ::toUtf8 > ::fromUtf8 > > and similar functions. I improved the QString class and toUtf8() works fine. But I get too much segfaults with other functions so I have to spend more time to it. You can put any QString class object to php's echo or print methods, please consider test/qstring.php and test/unicode.php. -- Thomas |
From: Ferenc V. <li...@ne...> - 2006-01-16 23:29:22
|
Hi! >> Does not work: >> $this->txtGuessPercents[$i]->$text =3D $tr["percent"]."%"; >> >> Error message: "Cannot access empty property". According to the Qt Well, actually that should be ->text, which dumps core, instead that error message. :-) > This is not possible. PHP-properties are provided as you can see in Ok, I did not even remember that C++ can do actions when setting a property! (Been too long time ago.) PHP could do that only via __set(), but maybe that would be too much overload. (Both to php_qt developers and CPU. :-) ) Reasonable. The only problem I could see, is that sometimes setting the property and using the access method has different effects on various checks and signals in Qt4. I don't know if that will cause problems, of course PHP programmers must take extra care of these changes, that's all. I am not sure about that, just browsing QLineEdit docs and thinking... > I improved the QString class and toUtf8() works fine. But I get too muc= h=20 > segfaults with other functions so I have to spend more time to it. > You can put any QString class object to php's echo or print methods, pl= ease=20 > consider test/qstring.php and test/unicode.php. Thanks you! :-) First a little note: $txt =3D new QString(""); $txt->toUtf8(); segfaults. While seeing your examples, I cannot see how it will work with non-English strings. E.g. since PHP can implement only one of the 8 constructors, which one will it be? Or will use use "is_a()" to implement more? Sounds very difficult. QString () QString ( const QChar * unicode, int size ) QString ( QChar ch ) QString ( int size, QChar ch ) QString ( const QLatin1String & str ) QString ( const QString & other ) QString ( const char * str ) <- looks to be this one now QString ( const QByteArray & ba ) Seeing from the "test/unicode.php": $QString =3D new QString("hello"); I really don't know. If I upload the object with "h=C3=A1llo" instead, it still prints the string back, I use KWrite in "UTF-8" mode for the test. Even the non-latin 1 "=C5=91" character works right! And both "toUtf8" an= d simple "echo" prints the characters right. (I use a Konsole configured for UTF-8.) (I tested with strings from the database too, same result.) So it looks like the string is just travelling in binary format. (?) There is no such thing as "plain text"! :-) Do you remember my old screenshot with broken utf-8 text: http://www.wpsnet.hu/~lion/gui.png ? I think that could be fixed only with QString, something like: $text =3D QString::fromUtf8($my_database_fetched_variable); // static m. $myLineEdit->setText($text); // (Passing QString there drops core.) Ok, I stop testing CHARS for now, and leave you with your original schedule, just please, take a note on charset support. ;-) Thanks, Ferenc |
From: Thomas M. <tm...@ip...> - 2006-01-17 00:15:07
|
=46erenc Veres wrote on Dienstag, 17. Januar 2006 00:29: > While seeing your examples, I cannot see how it will work with > non-English strings. E.g. since PHP can implement only one of the 8 > constructors, which one will it be? Or will use use "is_a()" to > implement more? Sounds very difficult. > QString ( const char * str ) <- looks to be this one now 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); Normally it is possible to provide all constructors, but the others are sti= ll=20 broken in the current version. Next time I will fire up an improved kalyptu= s=20 script again to solve it. > Seeing from the "test/unicode.php": > > $QString =3D new QString("hello"); > > I really don't know. If I upload the object with "h=C3=A1llo" instead, it > still prints the string back, I use KWrite in "UTF-8" mode for the test. it should print "h=C3=A1llo" to console. > Even the non-latin 1 "=C5=91" character works right! And both "toUtf8" and > simple "echo" prints the characters right. (I use a Konsole configured > for UTF-8.) (I tested with strings from the database too, same result.) =46ine. > So it looks like the string is just travelling in binary format. (?) The string is stored in the QString object. The zend engine passes it from= =20 your code to the object. In your tests you have proven that it works. > There is no such thing as "plain text"! :-) Do you remember my old > screenshot with broken utf-8 text: http://www.wpsnet.hu/~lion/gui.png ? > I think that could be fixed only with QString, something like: > > $text =3D QString::fromUtf8($my_database_fetched_variable); // static m. > $myLineEdit->setText($text); // (Passing QString there drops core.) The fromUtf8 function does not work for me, I got segfaults. What is with this piece of code: $text =3D new QString($my_database_fetched_variable); $myLineEdit->setText($text); 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 normal= =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. =2D-=20 Thomas |
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 |
From: Thomas M. <tm...@ip...> - 2006-01-17 09:58:58
|
=46erenc Veres wrote on Dienstag, 17. Januar 2006 02:12: > 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? Trolls wrote: "Constructs a string initialized with the ASCII string str." And next "str is converted to Unicode using fromAscii()." > 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.) Lets finish QString and test all functions there. All I have seen in php=20 internals stores strings binary. Maybe, we have luck. > 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. We will see. There are toAscii() toLatin1 toUtf8 =2E.. One of these I can use for the magically __toString() method. =2D-=20 Thomas |
From: Thomas M. <tm...@ip...> - 2006-01-18 22:40:24
|
Thomas Moenicke wrote on Dienstag, 17. Januar 2006 10:58: > Lets finish QString and test all functions there. All I have seen in php > internals stores strings binary. Maybe, we have luck. Ok, I improved the argument handlers, now I have no more segfaults, toUtf8() returns any cryptical signs ;) -- Thomas |
From: Ferenc V. <li...@ne...> - 2006-01-20 22:46:21
|
Hi, Thanks for the answers! Thomas Moenicke wrote: > Ferenc Veres wrote on Dienstag, 17. Januar 2006 02:12: >=20 >>Then what is the input encoding?=20 .. > Trolls wrote: > "Constructs a string initialized with the ASCII string str." > And next > "str is converted to Unicode using fromAscii()." I did some tests, with Tutorial 1 in both PHP_QT and C++, and I think it can accept iso-8859-1 encoded characters too. Not only the first 127 ASCII characters display right on the Tutorial 1 button, but if you use 127 to 255 byte values, they display like those byte codes look in iso-8859-1 character set! (latin1) Fine. Not useful for Hungarian, but an acceptable extra feature. ;-) > Lets finish QString and test all functions there. All I have seen in ph= p=20 > internals stores strings binary. Maybe, we have luck. For example entering "=C5=B1" in iso-8859-2 edited source code will displ= ay "=C3=BB" on a button, as that is the same BYTE VALUE in iso-8859-1. It's okay. I just needed to know, it expects Latin1 characters. Now I can also test toUtf8(). :-) > We will see. There are > toAscii() > toLatin1 > toUtf8 My test results confirm that everything is alright! ;-) From tests/unicode.php, changing the input string to > 127 characters, ->toUtf8() displays characters right on my Konsole, so I think, the latin1 to utf-8 conversion is done. (Of course if I edit in Latin1 or Latin2, I can see different characters on the same byte code, but both the characters display as their latin1 value on the button label or console. KWrite is a very good editor to test this.) Printing the string with echo, prints binary dirt, that's also correct, because the byte sequence of the latin-1 characters have no meaning if for my utf-8 console. Displaying on and inside widgets, will be up to Qt, when we can pass QString to them. I'll have my input data in utf-8, so I think fromUtf8 could be used, but currently I cannot call that method on QString. Will it be implemented as static method like the C++? (If yes, I think I will need an example on how to call. :-) ) Many thanks and keep up the good work! ;-) Ferenc ps: may I report problems with any widgets appearing in the source? If yes, then I think QLabel is completely broken. :-) |
From: Thomas M. <tm...@ip...> - 2006-01-21 08:43:37
|
Ferenc Veres wrote on Freitag, 20. Januar 2006 23:46: > I'll have my input data in utf-8, so I think fromUtf8 could be used, but > currently I cannot call that method on QString. Will it be implemented > as static method like the C++? (If yes, I think I will need an example > on how to call. :-) ) we could make a configure option '--enable-unicode' or alike for providing unicode strings to the underlying php system. So a echo $myQString; would echo the unicode string instead of the ASCII string. -- Thomas |