Important: Please read the Qt Code of Conduct -

Table Widget <- uint8_t *

  • 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;
    uint8_t *prueba;
    prueba=new uint8_t[IP_MAXPACKET];

    any help?

    Thanks in advance.

  • Lifetime Qt Champion

    @mgpmad said:
    it returns the QTableWidgetItem *
    So maybe you mean to take its text ?

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

    Each item can have data besides its text
    Would be a safer way to store it.

  • 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?


  • Lifetime Qt Champion

    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?

  • 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);

  • Lifetime Qt Champion

    Ok. I understand.
    The Data member is QVariant and can store all types.
    But one need to register it.
    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.

Log in to reply