Table Widget <- uint8_t *
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.
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);
Thanks in advance.
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?
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; 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);
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 back from it you would have to
copy unless you can just use the QByteArray.