how to convert QString to const char* (utf8)
-
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
-
@SGaist void func(const char* xxx);
func(myString.toUtf8().constData()); -
It will work, but it's not the best thing to do from a readability point of view.