Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How can I assign a byte value to a specific index of a bytearray without causing its size to change??

    General and Desktop
    3
    6
    3775
    Loading More Posts
    • 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.
    • P
      phamtv last edited by

      this seems like a no brainer but I can´t for the life of me figure this out...

      I tried...
      @
      TX_Buffer.replace(sizeof(TX_Msg), 1, &((DI.mid(2, 2).toInt(&ok, 16) + 0x33) % 256));
      @

      but get and error :
      error: lvalue required as unary ‘&’ operand

      1 Reply Last reply Reply Quote 0
      • D
        danilocesar last edited by

        Try this:
        @QByteArray ba("Hello world");
        char *data = ba.data();
        ba.data()[1] = 'B';
        qWarning() << ba; //shows "HBllo world"
        @

        size() always returns 11.

        <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
        Software Engineer

        1 Reply Last reply Reply Quote 0
        • G
          goetz last edited by

          Your third argument

          @&((DI.mid(2, 2).toInt(&ok, 16) + 0x33) % 256)@

          to replace is not an C++ object (which you can get an address with &), but an integer.

          Danilo:
          @ba[1] = 'B';@
          should do the trick even shorter

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply Reply Quote 0
          • D
            danilocesar last edited by

            Outch, my bad... You're right.

            <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
            Software Engineer

            1 Reply Last reply Reply Quote 0
            • G
              goetz last edited by

              No problem - it was a long and hard week, so even the cutest brain gets exhausted sometimes :-)

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply Reply Quote 0
              • P
                phamtv last edited by

                thanks guys!

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post