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. Table Widget <- uint8_t *
Forum Updated to NodeBB v4.3 + New Features

Table Widget <- uint8_t *

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.7k 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.
  • M Offline
    M Offline
    mgpmad
    wrote on last edited by mgpmad
    #1

    Hi all,

    I've create a table widget to show data of packet which I receive with a raw socket.
    I want to insert the complete packet,which it has uint8_t * format, in one field.
    I've used this sentence to insert the data into the field.

     QTableWidgetItem(QString::asprintf((char *)data_packet)
    

    but when I try to get the data back , I don't get result I want.

    QTableWidgetItem *a;
    a=ui->Display_table->item(5,4);
    uint8_t *prueba;
    prueba=new uint8_t[IP_MAXPACKET];
    memcpy(prueba,a,sizeof(uint8_t)*IP_MAXPACKET);
    

    any help?

    Thanks in advance.

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

      @mgpmad said:
      Hi
      http://doc.qt.io/qt-5/qtablewidget.html#item
      it returns the QTableWidgetItem *
      So maybe you mean to take its text ?
      http://doc.qt.io/qt-5/qtablewidgetitem.html#text

      Its seems a bit messy to store data_packet as the caption.

      Each item can have data besides its text
      http://doc.qt.io/qt-5/qtablewidgetitem.html#setData
      Would be a safer way to store it.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mgpmad
        wrote on last edited by
        #3

        thanks for your quick answer
        What I really want is to insert a int8_t * into a field of the table, and I want to get it back later into the same format int8_t *
        Is that possible?

        Regards

        mrjjM 1 Reply Last reply
        0
        • M mgpmad

          thanks for your quick answer
          What I really want is to insert a int8_t * into a field of the table, and I want to get it back later into the same format int8_t *
          Is that possible?

          Regards

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

          @mgpmad
          Hi
          Yes it would be possible to store a pointer in the data section.
          But what does it point to?
          Later when you take it out again, the info it points to will still be valid?

          Could you show how data_packet is defined?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mgpmad
            wrote on last edited by
            #5

            Sorry I express myself wrongly

            I don't want to store the pointer,rather the information that pointer points.

            uint8_t *data_packet;
            data_packet=new uint8_t[65535];
            sock_promis=socket(PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
            recvfrom (sock_promis, data_recv, IP_MAXPACKET, 0, (struct sockaddr *) &from, &fromlen);
            memset(data_packet,0,sizeof(uint8_t)*65535);
            memcpy(data_packet,data,sizeof(uint8_t)*65535);
            
            mrjjM 1 Reply Last reply
            0
            • M mgpmad

              Sorry I express myself wrongly

              I don't want to store the pointer,rather the information that pointer points.

              uint8_t *data_packet;
              data_packet=new uint8_t[65535];
              sock_promis=socket(PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
              recvfrom (sock_promis, data_recv, IP_MAXPACKET, 0, (struct sockaddr *) &from, &fromlen);
              memset(data_packet,0,sizeof(uint8_t)*65535);
              memcpy(data_packet,data,sizeof(uint8_t)*65535);
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @mgpmad
              Ok. I understand.
              The Data member is QVariant and can store all types.
              But one need to register it.
              http://kunalmaemo.blogspot.dk/2010/11/storing-custom-class-in-qvariant.html
              Then you can use it directly.

              Alternatively you could a QByteArray
              it has constructor
              QByteArray(const char * data, int size)
              that would allow u to construct it easy from data_packet
              QByteArray is supported by QVariant directly and then
              the SetData and Data would just work.
              But to get a uint8_t[65535] back from it you would have to
              copy unless you can just use the QByteArray.

              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