Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Way to send all types of events, from a client to a server
hello to the whole community Qt Forum,
I have a question, I'm developing a client / server application, where the server has to do everything the client does, and vice versa, so I would like to know if there is a way to have the same events exchanged between the client and the server ;
ie, if the client selecting a text and highlights it, the server also needs to do the same thing;
I hope I was clear
Thanks in advance :)
- You need to exchange the data between client & server in some format.
- After receiving the data, you need to construct the your custom QEvent object.
- Send the event object using QApplication::postEvent(..) metdhod.
Pablo J. Rogina last edited by
so I would like to know if there is a way to have the same events exchanged between the client and the server ;
the server has to do everything the client does, and vice versa,
Really? at the same time?
So if client deletes the word "Hello" while server is highlighting that same word, what will happen?
@dheerendra Thank you for your reply...
I would really like to know how to exchange this information;
And where: in the main, or with a function connected to the manager of each event?
thanks for giving me the standard, I'll read it to understand more;
in practice it must do that, the purpose is to solve the problem of the CRDT, which I have already partially solved;
I need a kind of echo system, which repeats the same operations both on the client and on the server, then conflict management will come later ...
fcarney last edited by
Video game engines do this a lot. Even in single player games there can be the concept of client server. Usually it is client/server with server side authority with the client being corrected periodically. This prevents cheating. They usually feed events to both server and client. You may look at how video games engines do this. I know Torque 3D does this and I am guessing that UE4 and Unity probably have some method for this. I am sure there are a few video game related articles for this as well.
Kent-Dorfman last edited by
It sounds kinda VNC-like application, so you may want to look at the RFB protocol...
My thoughts, exactly. seems like he's just mirroring the interface across multiple machines.
Maybe the QtRemoteObjects module could be of interest.
oh ok, if you could tell me how I can capture all the events from a TextEdit class and send them to the server?
@danga96 You can implement an event filter: https://doc.qt.io/qt-5/qobject.html#installEventFilter
ok event filter is it useful for capturing an event of any kind .. but how can I send this event to the server that has the same effect as on the client that generated it?
but how can I send this event to the server that has the same effect as on the client that generated it?
Well, you need to serialise the event into a message containing all relevant information, send the message, de-serialise it on the receiver side and then use https://doc.qt.io/qt-5/qcoreapplication.html#postEvent to post the same event on receiver side. How to serialise is up to you, you need to define a protocol.
Also take a look at @Kent-Dorfman suggestion.