PDA

View Full Version : Issue connecting QButtonGroup with a function



di_zou
4th August 2011, 21:39
I have a bunch of buttons in a QButtonGroup that I am trying to connect with a function.


Here is my code:



def __init__(self):
addAppButtonGroup = QButtonGroup()
addAppButtonGroup.addButton(addCustomAppButton)
addAppButtonGroup.addButton(addAppleStoreAppButton )
addAppButtonGroup.addButton(addWebLinkButton)

addAppButtonGroup.setId(addCustomAppButton, 0)
addAppButtonGroup.setId(addAppleStoreAppButton, 1)
addAppButtonGroup.setId(addWebLinkButton, 2)

""Stuff to make buttons show up"""

self.connect(addAppButtonGroup, SIGNAL("buttonClicked(int)"), self.AddApplication)

def AddApplication(self, id):
print "hi"
print id



So all the buttons show up and I can click on them. However, when I click on them, nothing is printed to the screen.


Thanks.

Santosh Reddy
5th August 2011, 01:25
As a QtC++ programmer, I can say couple of things
1. You are missing SLOT() macro
2. Even if the slot gets called, the id variable will not be valid, as you have not mentioned the required signature in connect.
3. More over you cannot connect a signal with less parameters to slot with more parameters.
4. A slot should always have less than or equal number of parameters, as compared to the number of parameters of signal, and also all the type of the parameters should match

di_zou
10th August 2011, 19:12
As a QtC++ programmer, I can say couple of things
1. You are missing SLOT() macro
2. Even if the slot gets called, the id variable will not be valid, as you have not mentioned the required signature in connect.
3. More over you cannot connect a signal with less parameters to slot with more parameters.
4. A slot should always have less than or equal number of parameters, as compared to the number of parameters of signal, and also all the type of the parameters should match

All of this does not apply in Python.

I was able to fix my issue by changing all of the


addAppButtonGroup

to


self.addAppButtonGroup