void AddCheckBox()
{
QStringList list;
list<<"one"<<"two"<<"three";
foreach(QString number,list)
{
QCheckBox *button = new QCheckBox(number,this); //widget添加button
connect(button,SIGNAL(clicked()),this,SLOT(getButtonText()));
}
}
void getButtonText()
{
QCheckBox *button = (QCheckBox * )(sender()); //关键一步是利用sender()
qDebug()<<"button text:"<<button->text();
{
QStringList list;
list<<"one"<<"two"<<"three";
foreach(QString number,list)
{
QCheckBox *button = new QCheckBox(number,this); //widget添加button
connect(button,SIGNAL(clicked()),this,SLOT(getButtonText()));
}
}
void getButtonText()
{
QCheckBox *button = (QCheckBox * )(sender()); //关键一步是利用sender()
qDebug()<<"button text:"<<button->text();
}
转载出处:https://zhidao.baidu.com/question/682335788711330092.html