Results 1 to 4 of 4

Thread: bit by bit -> Binary File Reader

  1. #1
    Join Date
    Jun 2013
    Posts
    46
    Thanks
    24
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Question bit by bit -> Binary File Reader

    Good Day,

    I have a binary field, that I need to read bit by bit
    Is there a way to read in the actual binary values of a file.

    I got this so far, but it reads per byte(quint8)

    Qt Code:
    1. QDataStream in(&fileLoadBinary);
    2. int fileSize = fileLoadBinary.size();
    3. int i = 0;
    4. QStringList strngLst;
    5. quint8 tempVariable;
    6. while(i < fileSize)
    7. {
    8. in >> tempVariable;
    9. qDebug() << tempVariable;
    10. strngLst.append(QString(tempVariable));
    11. i++;
    12. }
    13. qDebug() << strngLst;
    To copy to clipboard, switch view to plain text mode 

    I want the actual binary values of the file(bit by bit)
    Whats the way forward?

    Help is much appreciated
    Kind Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: bit by bit -> Binary File Reader

    You can't read less than a byte each time.(at least, not to my knowledge)
    But why would you need a bit by bit read?
    I am sure the reason will turn out to be not valid.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    2lights (1st October 2013)

  4. #3
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: bit by bit -> Binary File Reader

    No way forward. The smallest amount of data you can access is a byte. Reading bit by bit isn't possible. Make a "buffered input stream" that reads byte by byte then process the read data bit by bit.

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

    2lights (1st October 2013)

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

    Default Re: bit by bit -> Binary File Reader

    QDataStream is not a general purpose binary stream, it is a serialization mechanism which expects additional data in the stream when reading from that stream. Use QFile::read() instead.
    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.


  7. The following user says thank you to wysota for this useful post:

    2lights (1st October 2013)

Similar Threads

  1. Help with Binary reader in qt ???
    By rajji_saini in forum Qt Programming
    Replies: 7
    Last Post: 20th September 2010, 06:34
  2. Open a binary file.
    By TJSonic in forum Qt Programming
    Replies: 13
    Last Post: 22nd July 2010, 23:32
  3. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 4th April 2009, 00:50
  4. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 18:04
  5. How to Print a doc file (or binary file) to printer
    By rmagro in forum Qt Programming
    Replies: 15
    Last Post: 5th September 2008, 16:46

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.