QT 中动态添加checkbox,怎么在触发的信号中获取点击的checkbox的text
展开全部
比如
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();
}
QObject * QObject::sender () const [protected]
返回发射信号类的指针,
我也是刚做出来,本来想着自己弄出来就不写了,想一想,写出来如果能帮助到别人,何乐而不为啦
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();
}
QObject * QObject::sender () const [protected]
返回发射信号类的指针,
我也是刚做出来,本来想着自己弄出来就不写了,想一想,写出来如果能帮助到别人,何乐而不为啦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询