Results 1 to 1 of 1

Thread: Reading float values from binary file

  1. #1
    Join Date
    Dec 2012
    Posts
    45
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Reading float values from binary file

    Hi I am writting an array of type double into a binary file use QDataStream. This works well with following code
    QFile file("sine.bin");
    file.open(QIODevice::WriteOnly);
    QDataStream out(&file);
    int i = 0;
    while( i < 100 )
    {
    for( double x = 0; x < 2.0 * 3.141 * 5; x += ( 3.141 / 10.0 ) )
    {
    yl[i] = sin(x);
    qDebug()<<" y1 =="<<yl[i];
    out <<yl[i];
    xl[i] = x;
    qDebug()<<" X1 =="<<xl[i];
    out <<xl[i];
    i++;

    }
    }
    Now i wan to read the same file but I am unable to do that i tried following coes
    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this);
    2. QFile fileToRead(fileName);
    3. fileToRead.open(QIODevice::ReadOnly);
    4. {
    5. QDataStream data (&fileToRead);
    6. // data.setByteOrder(data.LittleEndian);
    7.  
    8. double intb;
    9. data>>intb;
    10.  
    11. qDebug()<<intb;
    12. }
    To copy to clipboard, switch view to plain text mode 
    Any help will be great for me


    Added after 1 9 minutes:


    I solved it
    here is the code
    QString fileName = QFileDialog::getOpenFileName(this);
    QFile fileToRead(fileName);
    fileToRead.open(QIODevice::ReadOnly);
    {
    QDataStream data (&fileToRead);
    // data.setByteOrder(data.LittleEndian);

    while( !data.atEnd() ) {
    double intb;
    data>>intb;
    qDebug()<<intb;
    }
    }
    Last edited by shivendra46d; 4th January 2016 at 12:12.

Similar Threads

  1. Replies: 5
    Last Post: 16th November 2015, 20:18
  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

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.