PDA

View Full Version : QButtonGroup buttonClicked signal/slot problem



davidthewatson
27th February 2009, 01:53
Hello,

I'm connecting a QButtonGroup buttonClicked(int) signal to a slot in my MainWindow class as follows:

QObject::connect( leftButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onLeftButtonClicked(int)));

The connect works and I get the event. However, when my slot gets the event, id is always -1, no matter which button I press.

The slot looks like:

void MainWindow::onLeftButtonClicked(int id)
{
switch(id)
...

I have 8 buttons in the group. Any idea why I don't get the proper value?

I'm using Qt 4.3.4 on Windows XP SP2.

Thanks,
David

talk2amulya
27th February 2009, 05:41
have u called setId() for every button?

davidthewatson
28th February 2009, 15:21
Yes, this solved my problem. Thanks!

I guess what I don't understand is why QButtonGroup doesn't just init the id with a static incremementer automatically such that you'd get the id's in the order they were added without having to call setId.

-david

talk2amulya
28th February 2009, 17:24
lets not expect Qt to do everything for us..there has to be a reason we get paid for what we do :)