PDA

View Full Version : Need to do something in a safe place after all events done



Alundra
25th February 2021, 23:27
Hi!
I have an event listener from a file watcher and it can happen during an event of a tree widget.
The problem is I need to select a parent item if one selected item is deleted.
If I do this action during the current tree event, I get a crash from Qt, surely a conflict of events.
The only option I found is to emit a signal and connect to this signal in the same widget to ensure Qt will do the action in a safe place.
Is there any other method, less hacky, to achieve the same result?
Thanks!

d_stranz
26th February 2021, 04:41
This sounds strange. Events should not be able to interrupt the processing of another event, but apparently that might be what is happening in this case.

Your solution is not so hacky. Basically, by emitting a signal, you are ensuring that any slot connected to it will not be called until after processing of the current signal has completed.

Alundra
26th February 2021, 10:21
On this case it's fine because I named the signal "DirectoryChanged" so an external widget could connect to it to know when a refresh will happen.
So then I connected to this signal with a function named "InternalDirectoryChanged".
But yes if it was a widget that would be exposed to an external team in a company then if you had to play with multiple signal and connect surely depending on the case it can be a solution not so clean and need good documentation.
But I have to say I only met this special case here so maybe it's a very rare case.