Results 1 to 3 of 3

Thread: qbytearray qdatastream qfile writing/reading

  1. #1
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default qbytearray qdatastream qfile writing/reading

    Hi firstly it's what i am doing:
    Qt Code:
    1. QDataStream out(&data, QIODevice::WriteOnly);
    2. out.setVersion(QDataStream::Qt_4_7);
    3. out << (quint16) 0;
    To copy to clipboard, switch view to plain text mode 
    next i put some qstrings, integers to out
    after it i want to put data to the file:

    Qt Code:
    1. QFile file(tr("%1.txt").arg(receiver));
    2. file.open(QIODevice::WriteOnly);
    3. file.write(data);
    4. file.close();
    To copy to clipboard, switch view to plain text mode 

    and after this i've got in document:
    Qt Code:
    1. \00V\00\00\00\00\00\E8\00\00\00
    2. \00M\00i\00s\00i\00a\00\00\00<\00a\00d\00w\00a\00k\00e\00l\002\001\003\001\002\003\00k\00l\00a\00w\00j\00e\00a\00w\00l\00k\00e\00j\00 \002\002\002\002
    To copy to clipboard, switch view to plain text mode 

    what's the problem?

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

    Qt Code:
    1. QFile o_file(tr("%1.txt").arg(clientNumber));
    2. o_file.open(QIODevice::ReadOnly);
    3. QByteArray data2 = o_file.readAll();
    4. Form *w= new Form(this);
    5. w->show();
    6. w->show2(data2);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Form::show2(QByteArray a)
    2. {
    3. QString c(a);
    4. ui->text->append(c);
    5. }
    To copy to clipboard, switch view to plain text mode 

    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?
    Last edited by pekal; 26th October 2012 at 19:41.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qbytearray qdatastream qfile writing/reading

    Quote Originally Posted by pekal View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Oct 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qbytearray qdatastream qfile writing/reading

    yes you have right, sometimes my mind have problems with so easy things;] i'm searching where is no need

    thanks again;]

Similar Threads

  1. What is the best way to use QDataStream or QFile
    By lni in forum Qt Programming
    Replies: 5
    Last Post: 1st October 2011, 06:42
  2. Help with QDataStream and QByteArray
    By P@u1 in forum Qt Programming
    Replies: 1
    Last Post: 28th June 2011, 00:25
  3. QTcpSocket QDataStream QByteArray
    By Grimlock in forum Newbie
    Replies: 1
    Last Post: 14th December 2009, 22:47
  4. Replies: 9
    Last Post: 25th July 2009, 13:27
  5. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.