[Solved ... kind of] Convert long ascii hex value to long
I have a long that I get as String (QByteArray) in hex ascii notation: "01000015" (i.e. KeyDown value).
I've looked for a function to convert this to a long to use it as KeyVal but could not find it.
Are you thinking of something like QByteArray::fromHex("0xFF").toLong() ?
Looks pretty much like it, but I dont get it to work.
I get the value in like "+t 01000015" and then remove the beginning and try to use it as keycode:
QKeyEvent key(QEvent::KeyPress, QByteArray::fromHex(data).toLong(), Qt::NoModifier);
That is not working.
Final implementation target looks somewhat extended like:
"+t 01000015 02000000 6"
I am getting full key events as QByteArray over a serial input and need to forward it to a widget.
If it were a string i could split it up easily with .section but the string type does not have a fromHex.
Solved it "the other way round":
Input comes now as dec value: i.e. 16777217
Copying QByteArray to QString
Filtering like: QKeyEvent key(QEvent::KeyPress, datastring.section(' ', 1, 1).toULong(), Qt::NoModifier)
Works so far, and can be extended.
It's sometime simpler like that :)
Glad you found a solution !