PDA

View Full Version : Connecting signals and slots from different process



Momergil
6th February 2014, 12:50
Hello!

There is a task a application of mine does eventually that consumes quite a lot of memory, while the rest of the system has to process lots of other tasks as well. For optimization purposes, I initially decided to create a QThread-based class that would perform this eventual task separately, while sending progressive signals to a QProgressDialog's setValue(int) slot to tell the user how things are going.

But lately I was thinking about the possibility of moving this task to a different process and control it using QProcess. If I actually end up doing this, how would I connect the signal from the separated process with the QProgressDialog's setValue(int) slot? Is there a way to connect a slot from a given process with a signal from another, child process? Or I would have to implement the communication through a different methodology? In this case, which would it be?


Thanks,


Momergil

stampede
6th February 2014, 13:16
If you are concerned about the overall system performance, remember that introducing new process is more expensive than starting one additional thread in already existing process.
I don't know the details of your implementation, but maybe you can just run this task asynchronously with QtConcurrent, without the need to use threads explicitly.
If you decide to go with QProcess, then no, there is no way to use "connect()" between objects living in two separate processes, you have to use some inter-process communication method, like shared memory, pipes etc. Probably the easiest thing to do would be to write the progress to stdout and read it in "parent" process using QProcess facilities (readyReadStandardOutput () signal and such).

Momergil
8th February 2014, 11:11
If you are concerned about the overall system performance, remember that introducing new process is more expensive than starting one additional thread in already existing process.

Hmm, actually my problem is to not overweight the main process, since it will have lots of mathematical and graphical operations to do continuously, and this other taks will be considerably heavy as well. In other words, my goal is related to my main process only.

I guess I'll have to think more carefully about this then... And do some reading about QtConcurrent :)

anda_skoa
8th February 2014, 15:59
One way to do something very similar to cross process signal/slot is using D-Bus.

Another option is to use QLocalServer/QLocalSocket and a simple protocol of your own design.

Cheers,
_