I try to use the code below :
while(!child.isNull())
{
connect(button, SIGNAL(clicked()), &mapper, SLOT(map()));
mapper.setMapping(button, child.attribute("value"));
vLayout->addWidget(button);
child = child.nextSiblingElement("choice");
}
connect(mapper,
SIGNAL(mapped
(const QString &)),
this,
SLOT(onbuttonClicked
(const QString &)));
while(!child.isNull())
{
QPushButton * button = new QPushButton(child.text());
connect(button, SIGNAL(clicked()), &mapper, SLOT(map()));
mapper.setMapping(button, child.attribute("value"));
vLayout->addWidget(button);
child = child.nextSiblingElement("choice");
}
connect(mapper, SIGNAL(mapped(const QString &)), this, SLOT(onbuttonClicked(const QString &)));
To copy to clipboard, switch view to plain text mode
in the SLOT I receive correctly the value passed
void Mainwindow::onbuttonClicked(const QString& value)
{
// value is here to identify the button
QPushButton* button
= qobject_cast<QPushButton
*>
(sender
());
}
void Mainwindow::onbuttonClicked(const QString& value)
{
// value is here to identify the button
QPushButton* button = qobject_cast<QPushButton*>(sender());
}
To copy to clipboard, switch view to plain text mode
the button object is always NULL, why this ?
I want to retrieve button name but the sender is always NULL..
Bookmarks