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

 1 void AddCheckBox()
 2 {
 3   QStringList list;
 4   list<<"one"<<"two"<<"three";
 5   foreach(QString number,list)
 6   {
 7     QCheckBox *button = new QCheckBox(number,this); //widget添加button
 8     connect(button,SIGNAL(clicked()),this,SLOT(getButtonText()));
 9   }
10 }
11 void getButtonText()
12 {
13   QCheckBox *button = (QCheckBox * )(sender()); //关键一步是利用sender()
14   qDebug()<<"button text:"<<button->text();
15 }
原文地址:https://www.cnblogs.com/ybqjymy/p/14595498.html