2010年10月23日 星期六

Convert QString to Char*

If you went to convert prototype QString to char*,you can using this method:

int main(int argc, char **argv)
{
QApplication app(argc, argv);
QString str1 = "Test";

//method 1
strcpy(c_str2,str1.toUtf8());

//method 2
QByteArray ba = str1.toLatin1();
const char *c_str2 = ba.data();

printf("str2: %s", c_str2);
return app.exec();
}

沒有留言:

張貼留言