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. Avoid signal editingFinished() to be sent twice on hide()
Forum Updated to NodeBB v4.3 + New Features

Avoid signal editingFinished() to be sent twice on hide()

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 4.4k Views 3 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.
  • T3STYT Offline
    T3STYT Offline
    T3STY
    wrote on last edited by A Former User
    #1

    I have a QLineEdit widget and when it looses focus or editing is finished by pressing the enter key it should disappear. So I connected a slot to it where I call the hide() method. With a few qDebug messages I have noticed that the signal editingFinished() is sent twice; the first time it is sent when I finish editing or the widget looses focus, the second time it is sent when I call hide() on the widget. The double-call does not have any side-effects on my code, but the slot has a few tasks that might require some time to complete, and I would like to avoid doing twice those tasks.

    How can I avoid sending the editingFinished() signal when I call hide()?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by A Former User
      #2

      Hi,

      You can call:

      lineEdit->blockSignals(true);
      lineEdit->hide();
      lineEdit->blockSignals(false);
      

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T3STYT Offline
        T3STYT Offline
        T3STY
        wrote on last edited by
        #3

        yes, that worked perfectly, thanks!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          Since it's working as you want it, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kaluss
            wrote on last edited by Kaluss
            #5

            Hi,
            @SGaist
            Regarding your answer.
            Do you have any idea how can I do it in elegant way if it's not situation when I closing or hiding window.
            I have situation where the slot is called twice if user performs action.
            If I start block signaling it works and action is performed only once, but I need to unblock signaling for further user operations.

            My first idea is to start timer for unlocking signaling.

            Do you maybe know other way for doing that?

            BR,
            Kaluss

            K 1 Reply Last reply
            0
            • K Kaluss

              Hi,
              @SGaist
              Regarding your answer.
              Do you have any idea how can I do it in elegant way if it's not situation when I closing or hiding window.
              I have situation where the slot is called twice if user performs action.
              If I start block signaling it works and action is performed only once, but I need to unblock signaling for further user operations.

              My first idea is to start timer for unlocking signaling.

              Do you maybe know other way for doing that?

              BR,
              Kaluss

              K Offline
              K Offline
              koahnig
              wrote on last edited by
              #6

              @Kaluss

              How about QSignalBlocker?
              It seems to do what you need.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kaluss
                wrote on last edited by Kaluss
                #7

                Hi,
                @koahnig
                I will try this, but I suppose it won't work for me, because I tried already to:

                void myFunc(){
                lineEdit->blockSignals(true);
                
                ....
                
                lineEdit->blockSignals(false);
                }
                

                And it doesn't work.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  What exactly is your use case ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kaluss
                    wrote on last edited by Kaluss
                    #9

                    @SGaist
                    I got function:

                    void calculateSLot()
                    {}
                    

                    It's connected to editingFinished() signal of QLineEdit object.
                    When calculations will be performed and function will exit, my system must be ready to processing next actions.

                    If I use above examples the second call of the function is executed anyway.
                    At the moment my only idea is to set timer and block signal on function exit and unblock it when timer expires.

                    K 1 Reply Last reply
                    0
                    • K Kaluss

                      @SGaist
                      I got function:

                      void calculateSLot()
                      {}
                      

                      It's connected to editingFinished() signal of QLineEdit object.
                      When calculations will be performed and function will exit, my system must be ready to processing next actions.

                      If I use above examples the second call of the function is executed anyway.
                      At the moment my only idea is to set timer and block signal on function exit and unblock it when timer expires.

                      K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #10

                      @Kaluss

                      Did you check that you have connected editingFinished() only once?

                      The initial post has been concerning to avoid the emit of signal editingFinished under the condition of hiding. Sometimes there duplicated signals when you are not carefully choosing multiple signals used. Under such conditions it may be good to block signals or when signals are emitted while you set values.

                      However, when you are using only editingFinished() there should be only one call to your slot. Therefore, when editingFinished() is always the source for calling you should better check why this is the case.

                      There are the dump routines for QObject dumpObjectTree and dumpObjectInfo helping you to inspect the connections to objects.

                      Your choice of using QTimer may work, but there different reasons that this might be a problem. For very short calculations that may sufficient, but longer calculations this may be system dependent. Waiting too short will not help and waiting too long may confuse the user.

                      Vote the answer(s) that helped you to solve your issue(s)

                      1 Reply Last reply
                      1

                      • Login

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