Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved ... kind of] Convert long ascii hex value to long
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • McLionM Offline
          McLionM Offline
          McLion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            It's sometime simpler like that :)

            Glad you found a solution !

            You're welcome

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved