PDA

View Full Version : Reading float values from binary file



shivendra46d
4th January 2016, 12:12
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

QString fileName = QFileDialog::getOpenFileName(this);
QFile fileToRead(fileName);
fileToRead.open(QIODevice::ReadOnly);
{
QDataStream data (&fileToRead);
// data.setByteOrder(data.LittleEndian);

double intb;
data>>intb;

qDebug()<<intb;
}
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;
}
}