PDA

View Full Version : qbytearray qdatastream qfile writing/reading



pekal
26th October 2012, 19:35
Hi firstly it's what i am doing:

QByteArray data;
QDataStream out(&data, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_7);
out << (quint16) 0;
next i put some qstrings, integers to out
after it i want to put data to the file:


QFile file(tr("%1.txt").arg(receiver));
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();

and after this i've got in document:

\00V\00\00\00\00\00\E8\00\00\00
\00M\00i\00s\00i\00a\00\00\00<\00a\00d\00w\00a\00k\00e\00l\002\001\003\001\002\0 03\00k\00l\00a\00w\00j\00e\00a\00w\00l\00k\00e\00j \00 \002\002\002\002

what's the problem?

after this i want to open file and show in text browser:


QFile o_file(tr("%1.txt").arg(clientNumber));
o_file.open(QIODevice::ReadOnly);
QByteArray data2 = o_file.readAll();
Form *w= new Form(this);
w->show();
w->show2(data2);


void Form::show2(QByteArray a)
{
QString c(a);
ui->text->append(c);
}

and after this i don't see anything, firstly why i got this funny data in document, and why i couldn't show it in my browser text?

wysota
26th October 2012, 20:32
firstly why i got this funny data in document
What did you expect to get?


and why i couldn't show it in my browser text?
If you save using QDataStream and load without using QDataStream then how do you expect to get the same result as you had in the beginning?

You do realize that QDataStream does not give you textual output, right?

pekal
26th October 2012, 21:51
yes you have right, sometimes my mind have problems with so easy things;] i'm searching where is no need

thanks again;]