how to convert QString to const char* (utf8)
-
//----------------------------
// 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 ?
-
@joaopagotto where is the utf-8 handling ?
-
Again, what is xxx ?
-
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
@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
-
It will work, but it's not the best thing to do from a readability point of view.