Results 1 to 10 of 10

Thread: How to write and read from binary files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question How to write and read from binary files

    Hello!

    I'm planning a software that will plot a graph using Qwt or OpenGL (yet not decided) and the data of the graph would be catch by reading a .bin file, but this is the first time I deal with binary files so I'm a "little" bit ignorant on how do I proceed.

    Before writing the actual software, I'm developing a second one to help me in my process of learning how to deal with binary files. This software has two QTextEdit side-by-side and have a "instant connection" between them (i.e. if one of them is edited, the other immediately should change base on what is written in the changed QTextEdit). But one of the QTextEdit is supposed to be connected with a .bin file and originally show what is written in the file in binary code (so one of the QTextEdit will show only a set of 0000 and 1111 and so on), while the other should be its translator, i.e. should show the binary code of the first QTextEdit in ASCII characters.

    Now I already noticed that to work in this project I will use QDataStream and QFile. But the problem is that I'm not familiar with QDataStream::readBytes() and readRayData(), and nether with the write functions. So for example in the beginning, when the QFile is opened and should show in on of the QTextEdit the bin data contained in the .bin file, I don't know which function to use in the place of QTextStream::readAll().

    Could somebody help me in this project? Which function do I use to read a binary code and show them in ASCII (e.g. 01000001 shows 65), how can I give a readAll() and how can I write an ASCII character and the software translate it to binary? And how can I make sure that the user will only write "0"s or "1"s in the QTextEdit for binary data, calling a warning if the user attempts to write a non-binary caracter? (i.e. try to put an ASCII char)


    Thanks!!


    Momergil



    Note: It's something like this I want to do: http://www.roubaixinteractive.com/Pl...ry_To_Text.asp
    Last edited by Momergil; 22nd November 2011 at 13:54. Reason: one more question

Similar Threads

  1. Replies: 2
    Last Post: 2nd November 2010, 05:15
  2. Using QT to read and write files over bluetooth FTP
    By deano in forum Qt Programming
    Replies: 0
    Last Post: 14th December 2009, 23:22
  3. Replies: 1
    Last Post: 27th August 2009, 05:41
  4. How can I read Binary files with Qt
    By geo_saleh in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2007, 10:37
  5. How to read/write sets of orderded numbers in binary
    By kaydknight in forum General Programming
    Replies: 3
    Last Post: 12th March 2007, 05:50

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.