c++ - Displays unwanted character while converting from QDataStream to QChar -
i have code below
qbytearray bla("abcde"); qdatastream ds(bla.right(bla.size()-1)); qchar c; ds>>c; qdebug()<<c; // prints '?' instead of 'b'
it prints out b if change code as
qint8 c; ds>>c; qdebug()<<qchar(c); // prints 'b'.
it's ok single character suppose, have lot of characters need make loop , cast every single of them . please suggest approach.
ds>>c;
equals ds>>c.unicode();
, has type ushort &
. while qbytearray contains char
s.
the correct way converting qbytaarray
sequence of qchar
be:
qbytearray bla("abcde"); qtextcodec *codec = qtextcodec::codecforlocale(); const qstring string = codec->tounicode(bla); foreach (const qchar &c, string) { qdebug() << c; }
Comments
Post a Comment