[Solved ... kind of] Convert long ascii hex value to long



  • Hi

    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.

    Any idea?
    Thanks, McL


  • Lifetime Qt Champion

    Hi,

    Are you thinking of something like QByteArray::fromHex("0xFF").toLong() ?



  • Thanks.
    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:

    data.remove(0,3);
    QKeyEvent key(QEvent::KeyPress, QByteArray::fromHex(data).toLong(), Qt::NoModifier);

    That is not working.

    btw fyi
    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.
    Thanks anyway.


  • Lifetime Qt Champion

    It's sometime simpler like that :)

    Glad you found a solution !

    You're welcome


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.