QTcpSocket write/send entire class?



  • Hi everybody,
    Is it possible to write via QTcpSocket an entire class?

    such like
    @
    void SimpleChatClient::sendMessage()
    qtcpsocket()->write(instance_of_any_class)@

    @
    void SimpleChatClient::receiveMessage()
    myinstance = instance_of_any_class)@

    ?

    thanks

    Sofar I am just able to send and receive strings.



  • You can write anything on a socket as you want. All the socket sees are bytes. So if you want to send an instance of a class, you would need to think of some way to represent the whole class as bytes so that the receiver knows how to construct the instance again.
    Also remember that tcp sockets work as streams so that not all the data you sent will arrive at the same time.



  • I am currently working on a simular project. I was looking at json and class serialization. Maybe check it out, it might be for you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.