qt-interest@trolltech.com
[Top] [All Lists]

Re: Writing one's own class on a socket

Subject: Re: Writing one's own class on a socket
From: Minh Tran
Date: Tue, 30 May 2006 13:09:24 +1000

Hello

I believe what you're after is object serialisation.

In a nutshell, you need to somehow convert your objects into a stream of bytes so that the socket is able to transmit them onto the network. This involves using QDataStream (or something equivalent) to convert all your class member variables into one byte array. Then on the receiving end, you need to do the opposite.

So in psudeo code

Create your custom object
Create temporary byte array
Create a DataStream and attach to the byte array
Stream members of custom object into the byte array via the DataStream
Write the byte array to the socket

Hope that helps.

Minh

Paul England wrote:
I'm writing a little app, which requires me to send a user-defined class
on a socket.  It looks like QDataStream is what I need, but all the
member functions I have tried won't work.  From what I could see,
writeRawBytes sounds good, but it moans when I try to compile.

My attempt to no avail was:

socket = new QSocket();
user_class my_class;

QDataStream ds(socket);
ds.writeRawBytes(my_class, sizeof(my_class);

--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/



--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>