QTcpSocket escribe una estructura de datos
Frecuentes
Visto 1,373 veces
0
I used to send an struct with C++ sockets, and now I'm trying to use QTcpSockets instead. This is the struct:
const unsigned int uiMessageSize = 4;
typedef struct {
unsigned char uc_stx;
unsigned char uc_add;
unsigned char uc_state;
unsigned char uc_eot;
unsigned char uc_unused_padding[1024];
} st_message;
So then, for writing I used to call write(sockfd, &messageToSend, uiMessagePcToMastSize);
Now I'm trying with: socket->write(&messageToSend, uiMessagePcToMastSize);
and doesn't work: no matching function for call to ‘QTcpSocket::write(mastControl::st_messagePcToMast*, const unsigned int&).
I have searched more info, and looks like I should convert the struct to a QDataStrem, or just a QByteArray. I don't really know how to del with this.
¿Alguna ayuda?
2 Respuestas
1
La documentación shows that the write function is overloaded with 1 function being qint64 QIODevice::write ( const char * data, qint64 maxSize )
, so casting to const char*
debería ser suficiente.
contestado el 03 de mayo de 12 a las 10:05
0
Just add a toQBytearray and add a constructor in the struct where you split the bytearray to the struct where you convert the data . Put a splitvalue Like # or ; between the datasets and when you receive the data on your server just use the above mentioned constructor
contestado el 03 de mayo de 12 a las 10:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c++ qt struct qtcpsocket or haz tu propia pregunta.
this link might help, stackoverflow.com/questions/2570679/serialization-with-qt - Kunal