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. how Can I convert QByteArray to int
Forum Updated to NodeBB v4.3 + New Features

how Can I convert QByteArray to int

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 560 Views 2 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.
  • D Offline
    D Offline
    dziko147
    wrote on last edited by
    #1

    Hello
    QCanBusFrame Rpm= device->readFrame();
    How can i convert QByteArray to int .
    I want convert Rpm to int .

    thank you

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

      Hi,

      QByteArray::toInt.

      You better check that the conversion is successful and ensure that the QByteArray only contains the int data you are expecting.

      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
      2
      • D Offline
        D Offline
        dziko147
        wrote on last edited by
        #3

        @SGaist thanks for your fast reply .
        I have one second question please .
        How can i convert a QCanBusFrame to int ?

        J.HilkJ 1 Reply Last reply
        0
        • D dziko147

          @SGaist thanks for your fast reply .
          I have one second question please .
          How can i convert a QCanBusFrame to int ?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @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#payload

          to 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


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          1
          • D Offline
            D Offline
            dziko147
            wrote on last edited by
            #5

            @J-Hilk thanks for your reply .
            No , there is more than one integer .
            So in this case how can do this :)

            J.HilkJ 1 Reply Last reply
            0
            • D dziko147

              @J-Hilk thanks for your reply .
              No , there is more than one integer .
              So in this case how can do this :)

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @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....


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              mrjjM 1 Reply Last reply
              2
              • J.HilkJ J.Hilk

                @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....

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @J-Hilk
                Hi
                I wonder if this made him happy
                https://forum.qt.io/topic/128252/no-viable-conversion-from-qcanbusframe-to-qreal/7

                1 Reply Last reply
                1

                • Login

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