Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget signals emitted when menu selected - how do I stop this?
Forum Updated to NodeBB v4.3 + New Features

QWidget signals emitted when menu selected - how do I stop this?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eos pengwern
    wrote on last edited by
    #1

    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

    @
    if (hasFocus()) {

    }
    @

    ...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? And how do I stop it?

    Many thanks,

    Stephen.

    [EDIT: code formatting, Volker]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Can you give us a samll, example, showing your problem?

      Which signals are send out from which widget, when you click on a menu item?

      What do you mean by re-send exactly? is it really send twice?

      It is normal, when you click the mouse somewhere, that the focus owner of before, looses focus for this.

      Thanks

      Gerolf

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eos pengwern
        wrote on last edited by
        #3

        Thank you for you reply.

        I've noticed in fact that this only seems to be happening with one type of widget in particular - a subclass of QLineEdit which is used for ~80% of the widgets on my GUI. With this the signals are sent multiple times; twice when the value is edited, and then again when any other widget in the GUI (not just a menu item) is selected.

        I'll have a look at the code for that subclass to see if I can figure out what's wrong with it.

        Stephen.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          From which signals exactly are you talking? I'm sure, not all signals are send twice? If you tell us, which are the problematic ones, we could perhaps help or explain...

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • E Offline
            E Offline
            eos pengwern
            wrote on last edited by
            #5

            I think I've pinned it down to the the QLineEdit::editingFinished() signal, which according to the documentation is emitted "when the Return or Enter key is pressed or the line edit loses focus".

            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 is that the signal is being emitted when I press the Enter key (which I do as a matter of habit) and again when the widget loses focus.

            I think I need to add some code to my subclass which intercepts QLineEdit::editingFinished() and checks whether the contents have changed since the signal was last emitted, before forwarding the signal if and only if the contents have changed.

            Stephen.

            1 Reply Last reply
            0
            • E Offline
              E Offline
              eos pengwern
              wrote on last edited by
              #6

              Yes indeed, that fixed it.

              Thank you for your input.

              Stephen.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved