PDA

View Full Version : How to send quint32 variable in server-client



sksingh73
23rd June 2010, 20:48
i am writing a server-client program. i am passing various messages between them. i am easily able to send qstream data type, but facing problem in sending quint32 data. my function for writing data is


void comn::sendMAC()
{
if(tcpSocket->isOpen())
{
QString str2 = QVariant( calc_mac ).toString(); //calc_mac is quint32
tcpSocket->write(QString(str2 + "\n").toUtf8());
qDebug() << "Sending to server: " << calc_mac;
clienttextEdit->append( "sending: " + str2);

}
}

- with above function, i am converting quint32 into qstring & then sending. but i am again stuck, because at receiver side i want data as quint32 & not qstring.
- there can be 2 solution for this:-
- send data in quint32 form only.
- or if sending in qstring, then convert back into quint32. but how??
-- please help.THANX

ChrisW67
23rd June 2010, 23:11
You listed two possible solutions; I am not sure what help you are expecting.

Put the bytes of your quint32 you want to send, in the order you want to send them, into a QByteArray and then write it to the QTCPSocket.
OR
Modify the receiver to put the bytes of the string into a buffer (QByteArray) and convert to uint. Read the QByteArray docs to find number conversion functions.


See also the same question here: http://www.qtcentre.org/threads/31881-sending-quint32-variable-in-socket