Reputation: 13264
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.
Any help?
Upvotes: 0
Views: 1517
Reputation: 14392
the documentation shows that the write function is overloaded with 1 function being qint64 QIODevice::write ( const char * data, qint64 maxSize )
, so casting to const char*
should be enough.
Upvotes: 1
Reputation: 83
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
Upvotes: 0