PDA

View Full Version : problem in QString



wagmare
23rd December 2008, 12:36
hi friends,



const char *str;
QString path;
path = lineEdit->text();
str = (const char *)path.latin1();
// str = (const char *)path.local8Bit());


but compilation gives error: ‘class QString’ has no member named ‘latin1’
or local8Bit() why its showing like this....
please help ..

caduel
23rd December 2008, 12:47
well, it is showing that because...
a) you are using Qt4 and that is simply the truth: there is no such method (there is QString::toLatin1(), though)
b) you are using Qt3 and forgot to #include <QString>

HTH

jpn
23rd December 2008, 12:48
QString::latin1() is Qt 3. In Qt 4 it's named a little bit different. Make sure to read the correct version of docs.

wagmare
23rd December 2008, 12:51
first thanks for reply guru :)

you are right i am using Qt4.4.3 .... i just follow one good example in net without considering
version .....

jpn
23rd December 2008, 13:28
Just notice that the example you've found is a bit problematic. QString::toLatin1() returns a QByteArray object. You store a pointer to the internal data of that temporary object. "const char* str" is a dangling pointer as soon as the QByteArray object goes out of scope. For more details, see TT knowledgebase: How can I convert a QString to char* and vice versa ? (http://trolltech.com/developer/faqs/faq.2007-01-30.9032238253)