Results 1 to 5 of 5

Thread: QDataStream and QDebug

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Question QDataStream and QDebug

    hi
    please point the error in the following code

    Qt Code:
    1. QDataStream stream;
    2. stream<<(qint32)12345;
    3. qint32 i;
    4. stream>>i;
    5. qDebug()<<i<<" i";
    To copy to clipboard, switch view to plain text mode 

    the output is
    Qt Code:
    1. 0 i
    To copy to clipboard, switch view to plain text mode 

    i expect the output to be 12345.

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

    Default Re: QDataStream and QDebug

    You have no QIODevice set.
    You should see a warning in the debug output about this/: "QDataStream: No device".

    The data stream must be created with a QIODevice either by passing it in the constructor or via setDevice.

  3. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QDataStream and QDebug

    thanks marcel

    but even after constructing a QDataStream that operates on QByteArray i am getting the same output

    heres the code

    Qt Code:
    1. QDataStream stream(&ar, QIODevice::ReadWrite);
    2. stream<<(qint32)12345;
    3. qint32 i;
    4. stream>>i;
    5. qDebug()<<i<<" i";
    To copy to clipboard, switch view to plain text mode 

    the output is
    Qt Code:
    1. 0 i
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QDataStream and QDebug

    It's a stream. Streams don't work like that. You will have to seek the underlying device to beginning, just like in this other thread of yours.
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    babu198649 (21st December 2007)

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QDataStream and QDebug

    thanks jpn

    it worked after using this statement

    Qt Code:
    1. stream.device()->seek(0);
    To copy to clipboard, switch view to plain text mode 

    how to copy one QDataStream to another QDataStream.
    Last edited by babu198649; 21st December 2007 at 11:47.

Similar Threads

  1. QDataStream and qDebug()
    By babu198649 in forum Qt Programming
    Replies: 1
    Last Post: 19th December 2007, 12:43

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.