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 chars.

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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -