qt 动态添加checkbox,并添加点击事件

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:"<text();

}

转载出处:https://zhidao.baidu.com/question/682335788711330092.html

你可能感兴趣的:(qt,CheckBox)