Solved Is it ok that QueuedConnection start every time a new copy of a function?
-
I have an issue or misunderstandig in understanding of how QueuedConnection and QThreads work. I have a controller class which contains a worker object that being moved to a QThread. From main I emit a signal to the controller class which emits signal (QueuedConnection) to the woker object to perform a particular task. In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object. But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?
-
@MikhailG when a signal queueConnetion type is emited, this signal is inserted at end of queue to be processed when the event loop is able to deliver the signal to slot
-
@MikhailG said in Is it ok that QueuedConnection start every time a new copy of a function?:
In the worker object in a while loop I call QApplication::ProcessEvents() so the signals could be delivered and dispatched to the worker object.
This is a very bad idea. Worker object should never try to control event loop of the main thread. Either spin a local event loop to do the waiting, or simply exit the thread when your work is done. Your thread controller can start a new thread / job when it gets the signal to do some work.
But it appears that every time I emit a signal to perform a task a new copy of a function from the worker has been started. Why is it so?
Can you rephrase this question? I don't understand what you mean.
If you mean that every signal emission
emit
causes your slot to execute, then that is exactly what should happen, normal behaviour. -
@sierdzio said in Is it ok that QueuedConnection start every time a new copy of a function?:
Can you rephrase this question? I don't understand what you mean.
Well when I emit a signal to the worker object I pass a parameter for debugging purpose. Than I emit another signal with a debug data and I can see in logs for previous call and for current call debug data.
//PrevCall data
"D:/Music"
"D:/Music"
"D:/Music"
"D:/Music"
"D:/Music"
"D:/Music"
"D:/Music"
AWESOME!
//NewCall data
"D:/ISO"
"D:/ISO"
"D:/ISO"
"D:/ISO"
"D:/ISO"
"D:/ISO"
//PrevCall data
"D:/Music"
"D:/Music"
"D:/Music"
"D:/Music" -
This post is deleted! -
@MikhailG do you call
connect
multiple times for the same signal/slot?if so, that would lead to multiply slot calls for one emit
-
@aha_1980 nope. One time
-
Hi,
Can you show your code ?
-
@SGaist I got an answer. Thank you.
-
@MikhailG can you share your solution?
-
@aha_1980 sure here I got all the answers. And I decided to read a book Summerfiled qt4 professional programming.