Converting Qbyte array to array and to double
-
Hello , I get some data from a CAN Bus . So my data is some float and some double .
What I did is :
float myData; double myDatadouble; QDataStream stream(data); qDebug() << data.size() << " Data Data&size" ; if (data.size()== 5){ quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::SinglePrecision); stream >> myData; // read data qDebug() << "this is data"<< myData ; QString DatatoString =QString::number(myData); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; } else { quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::DoublePrecision); stream >> myDatadouble; // read data qDebug() << "this is data"<< myDatadouble; QString DatatoString =QString::number(myDatadouble); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; }
I get only float converted , the double is usually "0" .
thankyou
-
Hello , I get some data from a CAN Bus . So my data is some float and some double .
What I did is :
float myData; double myDatadouble; QDataStream stream(data); qDebug() << data.size() << " Data Data&size" ; if (data.size()== 5){ quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::SinglePrecision); stream >> myData; // read data qDebug() << "this is data"<< myData ; QString DatatoString =QString::number(myData); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; } else { quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::DoublePrecision); stream >> myDatadouble; // read data qDebug() << "this is data"<< myDatadouble; QString DatatoString =QString::number(myDatadouble); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; }
I get only float converted , the double is usually "0" .
thankyou
-
@artwaw thanks for your reply . Ok I will remove the Qstring .
Also I get unreadable data like " 3.13891e-43 " for a array "0xff000000e0" .
I use a online converter and give the same value .
But there is a way to make it readable .
thank you
@dziko147
again: in the "else" part you haveqDebug() << "this is data"<< myDatadouble; QString DatatoString =QString::number(myData);
where I think you should have
qDebug() << "this is data"<< myDatadouble; QString DatatoString =QString::number(myDatadouble);
since you do not even set
myData
in that part. Hence your string contains rubbish, you don't even initialise the variable. -
Hello , I get some data from a CAN Bus . So my data is some float and some double .
What I did is :
float myData; double myDatadouble; QDataStream stream(data); qDebug() << data.size() << " Data Data&size" ; if (data.size()== 5){ quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::SinglePrecision); stream >> myData; // read data qDebug() << "this is data"<< myData ; QString DatatoString =QString::number(myData); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; } else { quint8 byte; stream >> byte; // skip first byte stream.setFloatingPointPrecision(QDataStream::DoublePrecision); stream >> myDatadouble; // read data qDebug() << "this is data"<< myDatadouble; QString DatatoString =QString::number(myDatadouble); Outputs[i]=DatatoString; qDebug() << "In outputs data" << Outputs[i]; }
I get only float converted , the double is usually "0" .
thankyou
-
@CP71 said in Converting Qbyte array to array and to double:
8! so doesn't you have a one spare byte in else as in float case?
no I usually get frame started with FF .
I mean than in the case of a float I get "FF + 4Byte data"
In the case of a Double I get "FF +7Byte data "
and here I skip the first byte
quint8 byte; stream >> byte; // skip first byte
-
@CP71 said in Converting Qbyte array to array and to double:
8! so doesn't you have a one spare byte in else as in float case?
no I usually get frame started with FF .
I mean than in the case of a float I get "FF + 4Byte data"
In the case of a Double I get "FF +7Byte data "
and here I skip the first byte
quint8 byte; stream >> byte; // skip first byte
-
@CP71 now how can make it readable .
For example I get " 3.13891e-43 " for a array "0xff000000e0" .
please