Slots execution order and catching menu/action clicks
-
I'm working on the plugin and want to catch some user actions with main program like clicking on menu items or toolbar buttons. For example, when some menu item was clicked I want to perfom some actions in my plugin in addition to the actions already associated with that menu item in main program.
I tried to connect to the corresponding action's
triggered()
signal like thisdef handler(): print('Action triggered') action.triggered.connect(handler)
But it works in a bit unexpected way. My handler executed only after main program slot. For example, if main program opens some dialog and waits for user input, my handler will be executed only after* user closes that dialog by accepting or rejecting it.
Then I tried to connect to the menu's
triggered()
signal instead, where menu is a top-level menu containing target action. In this case, when I press on the toolbar button, my handler executed immediately, but when same action triggered from the menu, my handler again executed after closing dialog.Finally I tried to connect to the menu's
triggered()
signal, where menu is a parent menu of the targed action. And in this case my handler always runs immediatelly: when pressing on the toolbar button and when pressing menu item.Can anybode explain to me why I see different results and is it possible to catch
triggered
signal without delays? Or maybe there is another method to catch user interation with toobars/menus -
I can't explain difference between case 2) and 3).
However, what you see in 1) is that signal-slot connections are always executed in order in which connections were made (hint: don't depend on this, though). So, when you connect in your plugin, you always do it after main program already had connected it's signals and slots - and thus your slots are executed after main program's, too.
Then in 3) you get immediate execution because (probably) there was no connection made in main program for that particular
triggered()
signal - you are first in queue.Why 2) and 3) show different behaviour - I don't know.