0

I need to convert a QTextStream to a QByteArray, and then back again. I found an example of QTextStream -> QByteArray by constructing a QTextStream(QBytearray) and then any text < < to the stream ends up in the bytearray.

But how about the other way? Probably a one liner but I can figure it out. Can someone post and explain?

TSG
  • 4,242
  • 9
  • 61
  • 121

1 Answers1

0

Check it out if your text stream works via file (maybe via socket):

QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) 
   return;

QTextStream in(&file);
QString text;    

text = in.readAll();
file.close();

text.QString::toUtf8(); //convert your data to byte array

To get your data back use: QString::fromUtf8(const QByteArray &str)

bogdyname
  • 358
  • 2
  • 10