c++ - Qt binary reading error in qDatastream -


i reading binary file produced sensor. having problem in reading float different precision (32 or 64). can read them in matlab (64 bit version) qt (32 bit version on windows) giving wrong values. can read till dtmth (please ref structure below) . after getting value inf baseline. value 0 in fact. can see, changed msb (littleendian). if keep bigendian, 0 baseline others values wrong then. desktop 64 bit.

i have checked number of bytes , correct. think problem machine precision.

qdatastream in(&file);             in.setbyteorder(qdatastream::littleendian);            params p;             in >> p.filetype;                           in >> p.projectid;            in >> p.datamin;                           in >> p.dtyear;            in >> p.dtmth;                          in >> p.baseline;            in >> p.startfrequ; 

where p structure defined as:

    struct params     {         quint8 filetype;            quint16 projectid;         double datamin;         quint16 dtyear;         quint8 dtmth;             float baseline;         double startfrequ;      }; 

i can read them in matlab. matlab 64 bit version read data types following:

matlab:         uint8 filetype;            uint16 projectid;         float64 datamin;         uint16 dtyear;         uint8 dtmth;             float32 baseline;         float64 startfrequ; 

let me know if missed details.

edit:

reading file:

    qstring filename = qfiledialog::getopenfilename(this, tr("open file"), qstring(),                tr("raw files (*.msr);;all files (*.*)"));             if (!filename.isempty()) {                qdebug("attempting open file..");                qfile file(filename);                if (!file.open(qiodevice::readonly)) {                    qmessagebox::critical(this, tr("error"), tr("could not open file"));                    return;                }                 qdatastream in(&file); 

thanks lot in advance.

which version of qt using? if version superior qt 4.6, default precision 64 bit, which means qt try read float 32 float 64. need manually set precision in.setfloatingpointprecision ( qdatastream::singleprecision);

       in >> p.filetype;                       in >> p.projectid;        in >> p.datamin;                       in >> p.dtyear;        in >> p.dtmth;            in.setfloatingpointprecision(qdatastream::singleprecision);        in >> p.baseline;        in.setfloatingpointprecision(qdatastream::doubleprecision);        in >> p.startfrequ; 

from comment seems issue. indeed, if set single precision, , try read p.datamin or p.startfrequ (64 bits), data stream read them 32 bits floats. , not p.datamin incorrect values after it.

for start, check suggestion worked use after last line

      if(in.status() == qdatastream::readcorruptdata){             qdebug() << "still doesnt work";       } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -