how to convert QString to const char* (utf8)
-
wrote on 2 Jun 2015, 08:04 last edited by opengpu2 6 Mar 2015, 01:23
how to convert QString to const char* (utf8)
(const char** )xxx.toLocal8Bit();(const char* )xxx.toUtf8();
which one is correct? -
wrote on 2 Jun 2015, 08:05 last edited by mcosta 6 Feb 2015, 08:07
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
-
wrote on 2 Jun 2015, 09:32 last edited by
Yep, you're right.
Sorry
-
wrote on 2 Jun 2015, 10:33 last edited by opengpu2 6 Mar 2015, 01:23
and i should use :
QString::fromUtf8((const char**)xxx);
to conver utf8 const char* to QString? -
What is xxx ?
-
wrote on 3 Jun 2015, 01:24 last edited byThis post is deleted!
-
Why would you need to call fromUtf8 on the const char * you just got from that QString ?
-
wrote on 3 Jun 2015, 12:18 last edited byThis post is deleted!
-
wrote on 3 Jun 2015, 20:12 last edited by
//----------------------------
// 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
wrote on 5 Jun 2015, 03:19 last edited by@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
1/22