PDA

View Full Version : hi,everyone,i have a question about "QButtonGroup"



to_guliang
28th April 2008, 13:08
i want to put some QAbstractButtons on the QButtonGroup,and then when one of them is pressed down,the signal"void QButtonGroup::buttonPressed ( QAbstractButton * button ) " is emitted.
my code:

ButtonGroup = new QButtonGroup(this);
QAbstractButton *button1;
button1 = new QAbstractButton(this);
ButtonGroup->addButton(button1);
there is error like this " cannot allocate an object of abstract type ‘QAbstractButton’"
it seems that the red color area is wrong

why? how can i realize the function? May I get the correct code?

thanks very much for any advices!!

aamer4yu
28th April 2008, 16:44
QAbstractButton is an abstract class I guess

For your code , it should be -


ButtonGroup = new QButtonGroup(this);
QPushButton *button1;
button1 = new QPushButton(this);
ButtonGroup->addButton(button1);

Hope it helps :)

to_guliang
29th April 2008, 02:20
thanks a lot, but the code doesn't work.
code:

QButtonGroup *btnGroup;
btnGroup=new QButtonGroup(this);
QPushButton *button1;
button1 = new QPushButton("LD",this);
btnGroup->addButton(button1,0);
button1->setGeometry(QRect(175,85,45,43));
connect(btnGroup,SIGNAL(ButtonClicked(int)),this,S LOT(show_IL(int)));
the code in show_IL:

if(i == 0)
{
QString str = "LD";
list->addItem(QString(str));
}
when the button1 is clicked, there is nothing show on my list! the slot doesn't work!
:(
please help me!

songqiming
29th April 2008, 02:58
you can connect every button to a signal solely or you should debug the program to see the value of i.

to_guliang
29th April 2008, 04:04
you can connect every button to a signal solely or you should debug the program to see the value of i.

i can realize connecting every button to a signal solely. i have 20 buttons, there are so many code to do like that.if i can use ButtonGroup,there will be much easy.
and i just debug the program to see the value of "i"; it proves that the slot doesn't work.
how should I do?:crying::crying:

aamer4yu
29th April 2008, 09:14
u mean the slot is not called ??

are u using the same line ??
signal is buttonClicked, not ButtonClicked .... is this the prob ??

jpn
29th April 2008, 09:14
It's "SIGNAL(buttonClicked(int))" not "SIGNAL(ButtonClicked(int))".

to_guliang
20th May 2008, 08:00
yeah, it's the problem,thanks for everyone
i'm sorry for delaying reply,i just come back from my vocation