Slot called twice when button pressed
-
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...
-
@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!
-
@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!
@Rohit_Athithya some things are meant to happen 😁
Glad you found the trick.