PDA

View Full Version : Main Event Loop response to all signals



^NyAw^
3rd October 2013, 10:58
Hi,

I have a Thread that emits "results" that have to be computed in the main Thread. The Thread emits a signal like "mySignal(bool)" so the result of the processing is passed to the main Thread. The problem is that the Main Event Loop joins a group of those signals into one slot call because the signals contain the same value:



true
true
true
true
...
true
false
true
true
true
...


Using a random value as a second argument will force the Main Event Loop to call the slot for every signal emitted?

I need this because in the Main Thread there is a IO card that must activate or deactivate some Outputs. For the complexity of the application it can't be done directly on the worker thread as could be there more than a thread that give results and then this results are joined and finally must activate the Outputs according this joined result.

Thanks,

wysota
3rd October 2013, 11:07
You can always use QCoreApplication::postEvent() and QObject::customEvent() instead of signals.

^NyAw^
3rd October 2013, 11:35
Hi,

I have tryied but the application was very slow. Maybe I did it wrong. I have deleted the code but it was like this:

worker thread


...
QCoreApplication::postEvent(myObject,new myEvent());
...


myClass


bool myClass::event(myEvent *event)
{
...
return true;
}


Thanks,

Hi again,

I have rewrited the code using "QCoreApplication::postEvent()" and it works fine. The application works as expected.

Using "QCoreApplication::postEvent()", all the events are processed?

So, using this way I don't need to use mutexes to lock the main and the worker threads about results.

Thanks,

wysota
3rd October 2013, 12:35
You are supposed to use customEvent() and not event().