Results 1 to 7 of 7

Thread: Reading binary into QVector

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Reading binary into QVector

    this seems to be working:

    Qt Code:
    1. //setup
    2. QVector<qint16> inVect;
    3. inVect << 0 << 3 << 0 << 16384 << -7460;
    4. QByteArray storage;
    5. QDataStream storageIn(&storage, QIODevice::WriteOnly);
    6. storageIn.writeRawData((const char*)inVect.data(), 10);
    7. //read back
    8. QDataStream storageOut(&storage, QIODevice::ReadOnly);
    9. QVector<qint16> outVect;
    10. outVect.resize(5);
    11. storageOut.readRawData((char*)outVect.data(), 10);
    12. foreach (qint16 current, outVect)
    13. qDebug() << current;
    To copy to clipboard, switch view to plain text mode 

    output is:
    Starting .../QtConsoleTest...
    0
    3
    0
    16384
    -7460

    .../QtConsoleTest exited with code 0

  2. The following user says thank you to tanderson for this useful post:

    stathis.stefanidis (16th December 2009)

Similar Threads

  1. Binary file reading using Structure
    By umulingu in forum Qt Programming
    Replies: 6
    Last Post: 25th July 2009, 11:35
  2. Binary file Reading.........
    By umulingu in forum Qt Programming
    Replies: 11
    Last Post: 20th July 2009, 06:18
  3. reading 4-bytes integer from binary file
    By maka in forum Qt Programming
    Replies: 8
    Last Post: 12th May 2009, 05:57
  4. QFile, QDataStream reading binary data
    By yren in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2009, 06:34
  5. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53

Tags for this Thread

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.