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; 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.
-
@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#textIts 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. -
@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?
-
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);
-
@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.