PDA

View Full Version : Reacting on Signal on qml side



codeman
29th January 2019, 11:33
Hello friends,

just a questions. is it normal that when I generate signals like this



//c++ side
for(int i = 0; i < 1000000; ++i){
emit testSignal(i);
}

//on qml side
....
onTestSignal:{
console.log(count)// or any other binding
.....
}


that its blocks my qml gui? Its realy not reactive!

How can I achieve nonblocking reaction to the signals?

anda_skoa
3rd February 2019, 09:34
When you run a loop on the main thread, the main thread is busy with that loop.
It if is busy with that loop, it can't do any event processing.

There are a number of options on how to change that:

1) Restructure the code to use a timer based iteration instead of a tight loop
2) Run the loop in a secondary thread
3) Call QCoreApplication::processEvents() in each loop iteration to do event processing before continuing with the loop.

Cheers,
_