如何把qstring转化为qbytearray
1个回答
展开全部
QByteArray与QString之间的转换:
示例:
[cpp] view plain copy
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
QByteArray s;
s.resize(5);
s[0] = '1';
s[1] = '2';
s[2] = '3';
s[3] = '\0';
s[4] = 'a';
cout << s << endl;
示例:
[cpp] view plain copy
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
QByteArray s;
s.resize(5);
s[0] = '1';
s[1] = '2';
s[2] = '3';
s[3] = '\0';
s[4] = 'a';
cout << s << endl;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询