Results 1 to 5 of 5

Thread: Spurious signals sent when menu item selected

  1. #1
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Spurious signals sent when menu item selected

    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.

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Spurious signals sent when menu item selected

    Instead telling a long story, give us some simple solid facts, like WHAT ARE THE NAMES OF THIS SIGNALS you are interested in? What is the reason to listen those signals?

  3. #3
    Join Date
    Aug 2009
    Posts
    50
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Spurious signals sent when menu item selected

    OK, fixed this...

    About 80% of the widgets on my GUI are subclasses of QLineEdit, and the problem was in fact only occurring with them. The offending signal was QLineEdit::editingFinished(), which according to the documentation is emitted “when the Return or Enter key is pressed or the line edit loses focus” (my emphasis).

    This is of course desirable behaviour, as we shouldn’t rely on the user pressing the Enter key each time they change a value. My problem was that the signal was being emitted when I pressed the Enter key (which I always do as a matter of habit) and again when the widget lost focus.

    So I added some code to my subclass to intercept QLineEdit::editingFinished() and check whether the contents had changed since the signal was last emitted, before forwarding the signal if and only if the contents had changed.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Spurious signals sent when menu item selected

    You can use QLineEdit::modified property for tracking changes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Spurious signals sent when menu item selected

    Review documentation of QLineEdit, maybe you need different signal.
    For example check QLineEdit::textEdited.
    We don't know what are you trying to achieve, you told us how you try to achieve something and you have problem with it. This kind of approach always give a poor results.

Similar Threads

  1. QListWidget selected item Row id.
    By nagabathula in forum Qt Programming
    Replies: 8
    Last Post: 20th December 2010, 17:08
  2. Disable menu item based to current control selected
    By Suppaman in forum Qt Programming
    Replies: 5
    Last Post: 9th December 2010, 07:33
  3. popupmenu for QTreeWidget's item when a particular item selected.
    By vinod sharma in forum Best Practices in Qt Programming
    Replies: 1
    Last Post: 22nd January 2010, 10:45
  4. Replies: 1
    Last Post: 20th January 2010, 08:38
  5. QListview set selected item
    By Freeman551 in forum Qt Programming
    Replies: 1
    Last Post: 25th December 2009, 00:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.