how to convert QString to const char* (utf8)
-
how to convert QString to const char* (utf8)
(const char** )xxx.toLocal8Bit();(const char* )xxx.toUtf8();
which one is correct? -
Hi,
if you need UTF-8 you should do
xxx.toUtf8().constData()
-
Hi,
It should rather be:
QString myString("foo/bar"); QByteArray inUtf8 = myString.toUtf8(); const char *data = inUtf8.constData();
Because
const char *data = myString.toUtf8().constData(); on the next line the QByteArray returned by toUtf8 has been destroyed
-
Yep, you're right.
Sorry
-
and i should use :
QString::fromUtf8((const char**)xxx);
to conver utf8 const char* to QString? -
What is xxx ?
-
This post is deleted! -
@SGaist
eg. the const char* got from QStringQString myString("foo/bar");
QByteArray inUtf8 = myString.toUtf8();
const char *data = inUtf8.constData(); -
@SGaist const char*
-
Why would you need to call fromUtf8 on the const char * you just got from that QString ?
-
@SGaist i need to convert with each other...thank you
-
@SGaist sometimes i need to convert the const char* (utf8) to QString
-
This post is deleted! -
//----------------------------
// QString to *charQString aux;
aux.append("aa");
aux.append("bb");char *texto;
texto = aux.toStdString().c_str();//----------------------------
// *char to QStringchar text[64];
strcpy(text, "text123");QString aux;
aux.append(text); -
@joaopagotto where is the utf-8 handling ?
-
@SGaist QString::fromUtf8((const char*)xxx); is this correct ? thank you..
-
Again, what is xxx ?
-
@SGaist it's const char* in utf8...eg. the const char* that converted from QString above...
thank you -
@SGaist
Hi,It should rather be:
QString myString("foo/bar");
QByteArray inUtf8 = myString.toUtf8();
const char *data = inUtf8.constData();Because
const char *data = myString.toUtf8().constData();
on the next line the QByteArray returned by toUtf8 has been destroyed//////////////////////////////////////
if as a function param, is this right?
void function(myString.toUtf8().constData()) {} -
void function(myString.toUtf8().constData()) {}
?It's not a valid function signature