Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Parsing a hexadecimal data and calculating checksum
Forum Updated to NodeBB v4.3 + New Features

Parsing a hexadecimal data and calculating checksum

Scheduled Pinned Locked Moved Unsolved QtWebEngine
9 Posts 4 Posters 890 Views
  • 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.
  • R Offline
    R Offline
    Rumeysa_135
    wrote on 2 Feb 2023, 07:48 last edited by
    #1

    Hello, I want to first parse a hexadecimal data coming from a device, then calculate the checksum, convert the data to decimal and print it on my screen.
    How can ı do that?

    J 2 Replies Last reply 2 Feb 2023, 07:50
    0
    • R Rumeysa_135
      2 Feb 2023, 07:48

      Hello, I want to first parse a hexadecimal data coming from a device, then calculate the checksum, convert the data to decimal and print it on my screen.
      How can ı do that?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Feb 2023, 07:50 last edited by
      #2

      @Rumeysa_135 Use https://doc.qt.io/qt-6/qstring.html#toInt to convert a string containing a hex number to an integer.
      Don't know what kind of checksum you need.
      "print it on my screen" - can be done using many widgets like QWidget, QTextEdit, ... - depends on how you want to show the data.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Rumeysa_135
        2 Feb 2023, 07:48

        Hello, I want to first parse a hexadecimal data coming from a device, then calculate the checksum, convert the data to decimal and print it on my screen.
        How can ı do that?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 2 Feb 2023, 07:51 last edited by
        #3

        @Rumeysa_135 How is this thread different to your older one: https://forum.qt.io/topic/142574/how-do-i-parse-string-arrays-in-qt ?
        You already got some answers there...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rumeysa_135
          wrote on 2 Feb 2023, 08:09 last edited by
          #4
          This post is deleted!
          J 1 Reply Last reply 2 Feb 2023, 08:23
          0
          • R Rumeysa_135
            2 Feb 2023, 08:09

            This post is deleted!

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 2 Feb 2023, 08:23 last edited by
            #5

            @Rumeysa_135 said in Parsing a hexadecimal data and calculating checksum:

            How can I integrate these two codes together?

            I don't understand the question.
            What do you mean with "integrate"?
            Simply call the code where needed.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            J 1 Reply Last reply 2 Feb 2023, 08:28
            0
            • J jsulm
              2 Feb 2023, 08:23

              @Rumeysa_135 said in Parsing a hexadecimal data and calculating checksum:

              How can I integrate these two codes together?

              I don't understand the question.
              What do you mean with "integrate"?
              Simply call the code where needed.

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 2 Feb 2023, 08:28 last edited by
              #6

              @jsulm said in Parsing a hexadecimal data and calculating checksum:

              I don't understand the question.

              I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"


              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.

              J J 2 Replies Last reply 2 Feb 2023, 08:51
              0
              • J J.Hilk
                2 Feb 2023, 08:28

                @jsulm said in Parsing a hexadecimal data and calculating checksum:

                I don't understand the question.

                I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 2 Feb 2023, 08:51 last edited by
                #7

                @J-Hilk I think byteArrayToUint32 is supposed to do that?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                J 1 Reply Last reply 2 Feb 2023, 08:52
                0
                • J jsulm
                  2 Feb 2023, 08:51

                  @J-Hilk I think byteArrayToUint32 is supposed to do that?

                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 2 Feb 2023, 08:52 last edited by
                  #8

                  @jsulm nope, it just exists when the size doesn't match

                  auto count = bytes.size();
                  if (count == 0 || count > 4) {
                  return 0;
                  }
                  

                  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
                  0
                  • J J.Hilk
                    2 Feb 2023, 08:28

                    @jsulm said in Parsing a hexadecimal data and calculating checksum:

                    I don't understand the question.

                    I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"

                    J Offline
                    J Offline
                    JonB
                    wrote on 2 Feb 2023, 10:12 last edited by JonB 2 Feb 2023, 10:14
                    #9

                    @J-Hilk said in Parsing a hexadecimal data and calculating checksum:

                    I think the OP's question is: "How do I take only 4 Bytes from my QByteArray, so that I can convert it into an int32?"

                    @jsulm nope, it just exists when the size doesn't match

                    So if you want to access 4 bytes (sizeof(int32)) for conversion use QByteArray QByteArray::mid(qsizetype pos, qsizetype len = -1) const. Otherwise if you want it to appear as an array of int32 (and you know byte ordering is correct) use reinterpret_cast<> to int array on the data.

                    1 Reply Last reply
                    1

                    1/9

                    2 Feb 2023, 07:48

                    • Login

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