how Can I convert QByteArray to int
-
Hi,
You better check that the conversion is successful and ensure that the QByteArray only contains the int data you are expecting.
-
@dziko147
I'm not an expert on CanBus, but I would say calling payload() on the Frame
https://doc.qt.io/qt-5/qcanbusframe.html#payloadto get the QByteArray and then toInt(), are you sure there's only 1 integer in that frame?
because it will probably fail, if there's more
-
@dziko147 well, that depends entirely on how you created the frame content on the other side of the bus.
The QByteArray contains Bytes, an int can have anything from 1 up to 8 bytes, typically int = int32_t = 4 bytes but thats not a guarantee, depending on the system it may be byte swapped or not, depending on endianness.
The first byte may actually not be part of the int, if a container was streamed/used on the other side etc....
-
@J-Hilk
Hi
I wonder if this made him happy
https://forum.qt.io/topic/128252/no-viable-conversion-from-qcanbusframe-to-qreal/7