Is there a way to read a certain amount of bytes from the serial and type cast it into int or float? I've read through the QByteArray document, but I don't really get it.
Is there a way to read a certain amount of bytes from the serial and type cast it into int or float? I've read through the QByteArray document, but I don't really get it.
Why not simply use QByteArray::toFloat() or toInt()?
What exactly didn't you get?I've read through the QByteArray document, but I don't really get it.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I've tried using toFloat(), but kept on getting 0
You're going to have to show some code if you want help in finding what's wrong.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
i.e.
QByteArray a("425AE78F");
float serial = a.toFloat();
qDebug() << serial;
I'm getting 0 instead of 54.72613. I don't think I'm doing it correctly.
This is example from QByteArray::toDouble doc :Do you see the difference ?Qt Code:
double a = string.toDouble(); // a == 1234.56To copy to clipboard, switch view to plain text mode
Are you saying that the string a is not a float that's why it fails to convert?
Of course. The number of float type and its text representation is two different things. You must go back to the basics of C ++.
As you can tell, I'm still learning c++. If you don't mind, could you give me an example of how does the float conversion works?
"4h\xB2\xC9\xBC'\xB2\xC9<\xBC\xF9K;\xD1\xEB\x7 F?"
The above is a chunk of my code, and I'm trying to convert it to float, but I couldn't get it to work. I really appreciate your help.
How is the data sent? The order of bytes is important.
Actually I'm reading the data from the serial. I have 9 values print out in arduino as double, so I want to read it 36 bytes at a time and convert it to float.
Bookmarks