In more than one of my Qt applications I've noticed that, whenever the menu bar is clicked, the last signal to have been sent from a widget within the GUI is re-sent before the menu action is invoked. Most of the time this doesn't matter; but on some occasions it matters very much.

In a few cases where the widget's signal is connected to one of it's own slots, it's straightforward to begin the slot with an

Qt Code:
  1. if (hasFocus())
  2. {
  3.  
  4. }
To copy to clipboard, switch view to plain text mode 

...block so that such spurious signals, not generated by the user actually clicking on the widget, can be ignored.

However, I've recently identified that this behaviour is responsible for several related bugs where the spurious signals are passed on through several layers of the program before being acted upon, so simply checking whether a particular widget has focus is not trivial to implement.

My question, therefore, is:

- why on earth does clicking on a menu item cause a signal to be emitted from a widget elsewhere on the screen? I can't find this behaviour documented anywhere.

- how do I stop it?

Many thanks,

Stephen.