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. pointer on struct to Qbytearray
Forum Updated to NodeBB v4.3 + New Features

pointer on struct to Qbytearray

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 423 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.
  • A Offline
    A Offline
    another_one
    wrote on 20 Apr 2023, 16:38 last edited by
    #1

    Hi All!

    Can anybody help in my question?, please

    I have got the following data structures:

    typedef struct {
        uint8_t prefix = 0xF0;
        uint8_t code = 0x00;
    } restart_t;
    
    typedef struct {
        uint8_t prefix = 0xF0;
        uint8_t code = 0x01;
        uint64_t start_addr = 0xFFFFFFFF15000020;
    } start_t;
    //
    typedef struct {
        uint8_t prefix = 0xF0;
        uint8_t code = 0x02;
        uint64_t start_addr = 0xFFFFFFFF15000020;
        uint32_t data_len = 0x00000000;
        uint8_t* data;
    } write_RAM_t;
    

    I need to transfer these data to qextserialport via QbyteArray
    And when I transfer restart_t by code below it transfer ok:

     restart_t restart;
     QByteArray dataArr2 = QByteArray(static_cast<char*>((void*)&restart),  sizeof(restart));
     if(port->isOpen())
     {
             port->write(dataArr2);
     }
    

    That verifies com-port monitor, I see F0 00 data sequense
    But when I try to send in the same manner start_t struct I see
    the following data sequence :
    ff 01 9a 00 00 00 00 00 20 00 00 b5 ff ff ff ff
    when I expect
    ff 01 ff ff ff ff b5 00 00 20
    So, as I understand, I need to point on start_t and write_RAM_t structures by pointer and then fill QbyteArray by these data
    But I dont know how to do it
    Please, help!

    C 1 Reply Last reply 20 Apr 2023, 16:43
    0
    • A another_one
      20 Apr 2023, 16:38

      Hi All!

      Can anybody help in my question?, please

      I have got the following data structures:

      typedef struct {
          uint8_t prefix = 0xF0;
          uint8_t code = 0x00;
      } restart_t;
      
      typedef struct {
          uint8_t prefix = 0xF0;
          uint8_t code = 0x01;
          uint64_t start_addr = 0xFFFFFFFF15000020;
      } start_t;
      //
      typedef struct {
          uint8_t prefix = 0xF0;
          uint8_t code = 0x02;
          uint64_t start_addr = 0xFFFFFFFF15000020;
          uint32_t data_len = 0x00000000;
          uint8_t* data;
      } write_RAM_t;
      

      I need to transfer these data to qextserialport via QbyteArray
      And when I transfer restart_t by code below it transfer ok:

       restart_t restart;
       QByteArray dataArr2 = QByteArray(static_cast<char*>((void*)&restart),  sizeof(restart));
       if(port->isOpen())
       {
               port->write(dataArr2);
       }
      

      That verifies com-port monitor, I see F0 00 data sequense
      But when I try to send in the same manner start_t struct I see
      the following data sequence :
      ff 01 9a 00 00 00 00 00 20 00 00 b5 ff ff ff ff
      when I expect
      ff 01 ff ff ff ff b5 00 00 20
      So, as I understand, I need to point on start_t and write_RAM_t structures by pointer and then fill QbyteArray by these data
      But I dont know how to do it
      Please, help!

      C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Apr 2023, 16:43 last edited by
      #2

      Has nothing to do with QByteArray or Qt but with aligning of the struct members, see e.g. here: https://carlosvin.github.io/langs/en/posts/cpp-pragma-pack/

      Don't know why you copy it to a QByteArray first instead directly calling write()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      A 1 Reply Last reply 20 Apr 2023, 16:50
      0
      • C Christian Ehrlicher
        20 Apr 2023, 16:43

        Has nothing to do with QByteArray or Qt but with aligning of the struct members, see e.g. here: https://carlosvin.github.io/langs/en/posts/cpp-pragma-pack/

        Don't know why you copy it to a QByteArray first instead directly calling write()

        A Offline
        A Offline
        another_one
        wrote on 20 Apr 2023, 16:50 last edited by
        #3

        @Christian-Ehrlicher

        thanks for quick replay!
        I cant do directly transfer cause port->write(QByteArray);

        C 1 Reply Last reply 20 Apr 2023, 16:52
        0
        • A another_one
          20 Apr 2023, 16:50

          @Christian-Ehrlicher

          thanks for quick replay!
          I cant do directly transfer cause port->write(QByteArray);

          C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 20 Apr 2023, 16:52 last edited by
          #4

          @another_one said in pointer on struct to Qbytearray:

          I cant do directly transfer cause port->write(QByteArray);

          So hard clicking on my link so you can find an overload of the write() function?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          A 1 Reply Last reply 20 Apr 2023, 17:15
          0
          • C Christian Ehrlicher
            20 Apr 2023, 16:52

            @another_one said in pointer on struct to Qbytearray:

            I cant do directly transfer cause port->write(QByteArray);

            So hard clicking on my link so you can find an overload of the write() function?

            A Offline
            A Offline
            another_one
            wrote on 20 Apr 2023, 17:15 last edited by
            #5

            @Christian-Ehrlicher
            Thank you for the link, I checked your link right away but I don't see write function application of qextserialport there
            Examples of the link based of streams and unfortunally I dont know how streams I can use with qextserialport

            C 1 Reply Last reply 20 Apr 2023, 17:17
            0
            • A another_one
              20 Apr 2023, 17:15

              @Christian-Ehrlicher
              Thank you for the link, I checked your link right away but I don't see write function application of qextserialport there
              Examples of the link based of streams and unfortunally I dont know how streams I can use with qextserialport

              C Online
              C Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 20 Apr 2023, 17:17 last edited by Christian Ehrlicher
              #6

              Apart from the fact that I don't see a reason to use QExtSerialPort in favor of QSerialPort, QExtSerialPort is also a QIODevice ...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1

              1/6

              20 Apr 2023, 16:38

              • Login

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