PDA

View Full Version : Pass custom events to another process



TTGator
12th January 2009, 20:28
I see some documentation about passing events from object to object, but is there a way to pass custom events to another process that was created by the qws server? (Embedded)

I'm assuming that QCOP is somehow involved... but I'm REALLY new to Qt, so any direction would be much appreciated!

jpn
12th January 2009, 20:42
Both processes can create an instance of QCopChannel with same channel name.

TTGator
12th January 2009, 20:51
I don't suppose there's any sample code out there that implements this is there?

TTGator
13th January 2009, 18:03
Bueller....

jpn
13th January 2009, 18:26
Receiver:


QCopChannel* channel = new QCopChannel("mychannel", this);
connect(channel, SIGNAL(received(QString, QByteArray)), this, SLOT(receiveMessage(QString, QByteArray)));


Sender:


QCopChannel::send("mychannel", message, data);

TTGator
13th January 2009, 21:44
So in your code example, "data" is supposed to be a custom event? It looks like it's supposed to be a QByteArray.

wysota
14th January 2009, 00:19
QCopChannel is not a way to send specifically "events", but any data. You can serialize an event on one end and deserialize it on the other end and dispatch it to the desired object. Of course both sides of communication have to be aware and ready for such mechanism - you can't communicate with any arbitrary application like that.

TTGator
14th January 2009, 14:05
Yes, I want to create a QServer process and have it start another QProcess and communicate with events. So I am trying to figure out how to first, create a custom event, and second, how to send that event from one process to the other.

Thank you for the order flow I need, so I guess I need to know how to:

1) Create a custom event (doc mentions extending QEvent, and somehow giving it an id above 1000 to designate it as a custom event)

2) serialize the event

3) send it on QCopChannel

4) deserialize the event

5) dispatch it

Is this not a common task that would have some sample code around for me to investigate? Or is there a better way to communicate between processes in an event driven manner?

wysota
14th January 2009, 20:50
I would skip step 1 and change step 4 to "create an event based on data received through QCop".

TTGator
14th January 2009, 22:02
You mean just pass something like the Event ID through QCop and convert it into an event on the receiving side? I want the events to be able to be sent to and from the client process. Seems like it would make more sense to have well defined events and send them. No? Otherwise you have to have values associated with events on both sides and keep track of them separately and make sure they are in sync.