Results 1 to 3 of 3

Thread: qbytearray qdatastream qfile writing/reading

Threaded View

Previous Post Previous Post   Next Post Next Post
  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.

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
  •  
Qt is a trademark of The Qt Company.