我以前用C++套接字發送一個結構,現在我試圖用QTcpSockets來代替。這是結構:QTcpSocket寫入一個數據結構
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;
那麼,寫我習慣叫write(sockfd, &messageToSend, uiMessagePcToMastSize);
現在,我試圖用:socket->write(&messageToSend, uiMessagePcToMastSize);
並不起作用:沒有匹配函數調用「與QTcpSocket: :write(mastControl :: st_messagePcToMast *,const unsigned int &)。
我搜索了更多的信息,看起來像我應該將結構轉換爲QDataStrem,或者只是一個QByteArray。我真的不知道如何解決這個問題。
任何幫助?
此鏈接可能有幫助,http://stackoverflow.com/questions/2570679/serialization-with-qt – Kunal