[Development] Read binary file
Yuriy Rusinov
yrusinov at gmail.com
Wed Dec 19 08:54:39 CET 2012
Dear colleagues !
I have to read binary file via Qt. In console application I make
FILE * fid5 = fopen ("./test_data/source.rgg", "rb");
...
for (int i=1; i<=na; i++)
{
fread (st+i-1, sizeof (unsigned long), nd2, fid5);
...
}
and all work fine. In Qt application I try
QString fileName = QFileDialog::getOpenFileName (this, tr("Select
source file"), QDir::currentPath(), tr("All files (*)"));
if (fileName.isEmpty())
return;
...
QFile * fData = new QFile (fileName);
for (int i=1; i<=na; i++)
{
char * colData = new char [nd2*sizeof (unsigned long)];
qint64 colLength = fData->readLine (colData, nd2*sizeof
(unsigned long));
if (colLength < 0)
{
qDebug () << __PRETTY_FUNCTION__ << QString ("Read error");
continue;
}
QByteArray buff (colData);
delete [] colData;
//qDebug () << __PRETTY_FUNCTION__ << i << buff;
QBuffer lBuf (&buff);
lBuf.open (QIODevice::ReadOnly);
QDataStream numStr (&lBuf);
quint64 num;
for (int ii=0; ii<nd2; ii++)
{
numStr >> num;
qDebug () << __PRETTY_FUNCTION__ << num;
st[ii] = num;
}
...
}
And for the same file in debug numbers do not read properly.
Thanks a lot.
--
Best regards,
Sincerely yours,
Yuriy Rusinov.
More information about the Development
mailing list