如何由QString转为char

 

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QString str1 = "Test";
    QByteArray ba = str1.toLatin1();/*转换必须步骤,必须保存在中间数组ba中再转存,否则如const char *c_str2=

                                                           str2.toLatin1().data(); 程序崩溃*/
    const char *c_str2 = ba.data();
    printf("str2: %s", c_str2);
    return app.exec();   
}

 

 


由char to QString:

QString string = QString(QLatin1String(c_str2)) ;

你可能感兴趣的:(c,String)