Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Slot called twice when button pressed
Qt 6.12 LTS is out! See what's new in the release blog

Slot called twice when button pressed

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 11 Posters 27.1k 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.
  • P Offline
    P Offline
    PetQter
    wrote on last edited by
    #15

    I created new project with button in MainWindow before my last post because I wanted to exclude if it is something in my code. Result is the same.
    Try please to comment both connect with released and clicked events and leave only connect with pressed handler and put breakpoint into pressed handler. Does not stops your code on breakpoint two times ?
    Try it please pushing button several times, in my case on first attempt it stops once and after F5 (continue) it does not stop again. But on several next attempts on every click it stops on breakpoint and after continue it stops on breakpoint second time.

    J.HilkJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #16

      Hi
      Only stops once here pr click. No matter how many times i click and f5.

      alt text

      1 Reply Last reply
      2
      • P PetQter

        I created new project with button in MainWindow before my last post because I wanted to exclude if it is something in my code. Result is the same.
        Try please to comment both connect with released and clicked events and leave only connect with pressed handler and put breakpoint into pressed handler. Does not stops your code on breakpoint two times ?
        Try it please pushing button several times, in my case on first attempt it stops once and after F5 (continue) it does not stop again. But on several next attempts on every click it stops on breakpoint and after continue it stops on breakpoint second time.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #17

        @PetQter
        works fine for me
        https://vimeo.com/user97690670/review/331922108/c1f17dd078


        just tested it with pressed, same behavior as clicked in the video


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2
        • P Offline
          P Offline
          PetQter
          wrote on last edited by
          #18

          I believe you. On my side it is probably depending on some internal dll responsible for events like mouse pressed. Maybe combination of Qt library, QtCreator version and Win 10 version. I must check it on another Windows developer's machine but it takes some days to have opportunity. I'd like to know if it has the same problem. I will write result to this post then.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            KidTrent
            wrote on last edited by
            #19

            Sorry for the necro, but I was having this same issue and I discovered it was because I was inheriting from another QDialog that I had made. Figured I would post and explain the issue...

            Steps to reproduce...

            • Make a base QDialog (let's call it BaseDialog).
            • Add a button to BaseDialog.
            • In QtDesigner, right click the button and click "Go to slot"->"clicked(bool)".
            • Add some debugging to the created slot so you can see it is being hit (qDebug("Slot Hit");).
            • Make another QDialog (SecondaryDialog).
            • Force SecondaryDialog to inherit from BaseDialog instead of QDialog (just edit the .h file of SecondaryDialog).
            • Create an instance of SecondaryDialog programmatically.
            • Run your program and click the button inside SecondaryDialog, it will be hit twice...

            I managed to solve this by manually adding the connect call in the BaseDialog constructor instead of depending on Qt to do it for me...

            JonBJ 1 Reply Last reply
            2
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #20

              Please provide a minimal, compilable example of the issue. You for sure did the connect twice.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              2
              • K KidTrent

                Sorry for the necro, but I was having this same issue and I discovered it was because I was inheriting from another QDialog that I had made. Figured I would post and explain the issue...

                Steps to reproduce...

                • Make a base QDialog (let's call it BaseDialog).
                • Add a button to BaseDialog.
                • In QtDesigner, right click the button and click "Go to slot"->"clicked(bool)".
                • Add some debugging to the created slot so you can see it is being hit (qDebug("Slot Hit");).
                • Make another QDialog (SecondaryDialog).
                • Force SecondaryDialog to inherit from BaseDialog instead of QDialog (just edit the .h file of SecondaryDialog).
                • Create an instance of SecondaryDialog programmatically.
                • Run your program and click the button inside SecondaryDialog, it will be hit twice...

                I managed to solve this by manually adding the connect call in the BaseDialog constructor instead of depending on Qt to do it for me...

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #21

                @KidTrent
                Most times people say slot hit multiple times turns out they have multiple connects. Not great idea to use the "named" auto-connections from Creator.

                Oh, I see @Christian-Ehrlicher has written this. Post an example.

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Hi,

                  Did you check that you are not connecting that signal twice ?

                  R Offline
                  R Offline
                  Rohit_Athithya
                  wrote on last edited by
                  #22

                  @SGaist I had done the same mistake of connecting the signal to a slot twice. I used pyqt5, and I had used the connect twice! Thus, calling the same message box element twice!

                  SGaistS 1 Reply Last reply
                  0
                  • R Rohit_Athithya

                    @SGaist I had done the same mistake of connecting the signal to a slot twice. I used pyqt5, and I had used the connect twice! Thus, calling the same message box element twice!

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #23

                    @Rohit_Athithya some things are meant to happen 😁
                    Glad you found the trick.

                    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
                    • aha_1980A aha_1980

                      @PetQter And just to add to @SGaist, how is your slot called (named)?

                      If it is named like on_pushButton_clicked(), then it is auto-connected to the button: https://doc.qt.io/qt-5/designer-using-a-ui-file.html#automatic-connections which can easily lead to a double connection.

                      Regards

                      A Offline
                      A Offline
                      Awesome
                      wrote on last edited by
                      #24

                      @aha_1980 Excellent, ta. Solved my problem.

                      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
                      • Unsolved