Results 1 to 3 of 3

Thread: QDataStream use

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QDataStream use

    I'm trying to use a QDataStream to serialize some data into a QByteArray. This needs to be done over multiple function calls: one to initialize it, one to add data to it called 1 to N times, and a call to use the data and finish up. I'm not sure how to do this (which might again be my lack of expertise with C++ and/or Qt). If I make the QDataStream a private class variable, there isn't a QDataStream.setDevice() for a QByteArray so I don't know how to init it, I can't use a QDataStream* as << and >> requires a QDataStream&.

    Help.

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDataStream use

    What about adding a pointer to a QDataStream member variable?
    And then:
    Qt Code:
    1. void SomeClass::initDataStream()
    2. {
    3. mDataStream = new QDataStream( yourByteArray );
    4. }
    To copy to clipboard, switch view to plain text mode 
    As for writing to the data stream, you can use:
    Qt Code:
    1. *mDataStream << someInput;
    To copy to clipboard, switch view to plain text mode 
    This is pretty clear. Don't forget to delete the data stream when you're finished with it.

    Regards

  3. #3
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDataStream use

    Thanks so much.

    Doug

Similar Threads

  1. Using QDataStream
    By toratora in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2007, 15:35
  2. QDataStream reading into QString
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 15th October 2006, 09:22
  3. QDataStream
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 23rd August 2006, 14:40
  4. Reading QByteArray from QDataStream Qt3.3
    By high_flyer in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2006, 20:23
  5. QDataStream >> QString
    By smalls in forum Qt Programming
    Replies: 2
    Last Post: 17th January 2006, 22:14

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.