Results 1 to 6 of 6

Thread: reading a binary file and put each byte of it it in a cell of float array

  1. #1
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default reading a binary file and put each byte of it it in a cell of float array

    hi all
    i have a binary file. i want to read it by Qfile and then put each Byte of it in a cell of float array.

    please help. thanks a lot
    Last edited by Alex22; 14th November 2015 at 17:13.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: reading a binary file and put each byte of it it in a cell of float array

    What have you tried?

  3. #3
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: reading a binary file and put each byte of it it in a cell of float array

    Quote Originally Posted by ChrisW67 View Post
    What have you tried?
    ChrisW67, i want like fread command in C++, to read a binary file in Qt and then put each byte in a cell of a char type array and then cast it to float and plot it by qwt. like this code in C:
    //open file
    FILE *fp;
    if ((fp = fopen(path, "rb")) == NULL)
    {
    perror("Error opening binary file");
    return 1;
    }
    //read from file to memory
    fread(&vm.memory, 1, 65536, fp);
    fclose(fp);

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: reading a binary file and put each byte of it it in a cell of float array

    QFile::read() into an existing char buffer or QByteArray

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

    Alex22 (15th November 2015)

  6. #5
    Join Date
    Nov 2015
    Posts
    128
    Thanks
    70
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: reading a binary file and put each byte of it it in a cell of float array

    Quote Originally Posted by ChrisW67 View Post
    QFile::read() into an existing char buffer or QByteArray
    thanks a lot ChrisW67, please give me an example with existing char like: char c[1024]

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: reading a binary file and put each byte of it it in a cell of float array

    Qt Code:
    1. const int bufferSize = 1024;
    2. char buf[bufferSize];
    3. ...
    4. qint64 bytesRead = file.read(buf, bufferSize);
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to ChrisW67 for this useful post:

    Alex22 (17th November 2015)

Similar Threads

  1. qt binary file writing and reading
    By seniorc in forum Newbie
    Replies: 9
    Last Post: 17th December 2013, 23:03
  2. Reading a binary file with QT
    By YuriyRusinov in forum Qt Programming
    Replies: 7
    Last Post: 21st December 2012, 07:14
  3. Binary file reading using Structure
    By umulingu in forum Qt Programming
    Replies: 6
    Last Post: 25th July 2009, 11:35
  4. Reading characters in Binary file.....
    By umulingu in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2009, 04:51
  5. Binary file Reading.........
    By umulingu in forum Qt Programming
    Replies: 11
    Last Post: 20th July 2009, 06:18

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.