QString to char* conversion

前端 未结 10 2079
予麋鹿
予麋鹿 2020-11-27 02:57

I was trying to convert a QString to char* type by the following methods, but they don\'t seem to work.

//QLineEdit *line=new QLineEdit();{just to describe w         


        
10条回答
  •  余生分开走
    2020-11-27 03:18

    the Correct Solution Would be like this

       QString k;
       k = "CRAZYYYQT";
       char ab[16];
       sprintf(ab,"%s",(const char *)((QByteArray)(k.toLatin1()).data()) );
       sprintf(ab,"%s",(const char *)((QByteArray)(k.toStdString()).data()));  
       sprintf(ab,"%s",(const char *)k.toStdString().c_str()  );
       qDebug()<<"--->"<

提交回复
热议问题