create multiple buttons with signal and slots
hi
i want to show multiple pushbuttons in the form dynamically!!! that is the number of pushbuttons i am showing ,will vary at runtime
.So i want to connect each button with signal and slot.i have created a function(i.e slot)
which will be called when any of the button is clicked..
Code:
for(int i=0;i<count;i++)
{
labelbed->setObjectName(bednumbersunderroom.at(i));
connect(labelbed,SIGNAL(clicked()),signalMapper,SLOT(map()));
signalMapper
->setMapping
(labelbed,labelbed
);
connect(signalMapper,
SIGNAL(mapped
(QWidget*)),
this,
SLOT(onbedclicked
(QWidget*)));
}
void Widget
::onbedclicked(QWidget* label
) {
msg->setText(label->objectName());
msg->show();
}
when any push button is clicked it displays message box but it displays as many messageboxes as push buttons...
for eg:if there are 3 push buttons,then if i click any one push button it displays 3 messagebox.But it should show only one messagebox..so how to do the signal slots
so that it will show one messagebox for each click!!!
thanks and regards
any help is highly appreciated
:confused::confused::confused:
Re: create multiple buttons with signal and slots
Code:
connect(signalMapper,
SIGNAL(mapped
(QWidget*)),
this,
SLOT(onbedclicked
(QWidget*)));
must be outside your loop! because then you conntect the signal mapper n-times.
Re: create multiple buttons with signal and slots
place that statement outside of your loop:
Code:
connect(signalMapper,
SIGNAL(mapped
(QWidget*)),
this,
SLOT(onbedclicked
(QWidget*)));
Re: create multiple buttons with signal and slots
Lykurg has already indicated that in 3 post ;)
Re: create multiple buttons with signal and slots
Of course he has; when I replied that answer was not there for me to see. (Otherwise I would not have posted anymore.)
Happens now and then. Sorry (not my fault, though).
Re: create multiple buttons with signal and slots
Quote:
Originally Posted by
spirit
Lykurg has already indicated that in 3 post ;)
Wow, do you see my post 3times??? I'm here in the diaspora, in the middle of woods with a bad wlan...
Re: create multiple buttons with signal and slots
Re: create multiple buttons with signal and slots
Guys, this is a thread that is a merge of two threads. Each of them replied in a different thread. Everything is ok (apart from the original author of the thread multi-threading).