QString与char*类型转换

时间:2021-12-03 15:56:50


QString 转 const char *:std::string = QString.toStdString();const char* = std::string.data();这种方式可能会失效,换用另一种方式:std::string sFile = (const char*)strFileName.toLocal8Bit(); const char * filename = sFile.data();

 

其他:

char* --------------QByteArray(const char*)-----------> QByteArray

char* --------------QString(const char*)-------------->QString

QByteArray -------------data()-------------------->char*

QByteArray ------------QString()------------------->QString

QString --------------toAscii()--------------------> QByteArray

QString -------------qPrintable()------------------>char*

或QString --------toLatin1()------QByteArray----------data()--------->char*