Conversion between QT char[] array and QByteArrya, QString

demand

Since using QT to write network-related interfaces, you need to customize the data structure, you need to call the char[] array variable during parsing, and you need to convert between QString and QByteArray

QByteArray转char[]

QByteArrya *qbyte = new QByteArray("hello world");
char cstr[20] = [];
//strcpy
strcpy(cstr,qbyte->data());

QString to char[]

  • Convert by QByteArray
QString *qstr = new QString("hello world");
char cstr[20] = [];
strcpy(cstr,qstr->toLatin1().data());
  • Convert through C++ stdstring
QString *qstr = new QString("hello world");
char cstr[20] = [];
strcpy(cstr,qstr->toStdString().data());

Use the constructor to convert char[] to QString and QByteArray

Guess you like

Origin blog.csdn.net/u013894391/article/details/105836188