摘自博客:/xgbing/article/details/7771898
QByteArray与QString之间的转换:
示例:
[cpp] view plain copy
在CODE上查看代码片派生到我的代码片
QByteArray cstr("abcd"); QString s = cstr; QByteArray cstr("abcd"); QString s; s.prepend(cstr); QString s("hello"); QByteArray cstr = s.toAscii(); QString s("hello"); QByteArray cstr = s.toLatin1();
QByteArray类同样不以’\0’为结尾:如
[cpp] view plain copy
在CODE上查看代码片派生到我的代码片
QByteArray s; s.resize(5); s[0] = '1'; s[1] = '2'; s[2] = '3'; s[3] = '\0'; s[4] = 'a'; cout << s << endl;