【发布时间】:2014-03-09 02:55:55
【问题描述】:
我在一个项目中使用Wt C++ 库。我正在尝试使用connect(...) 功能将插槽连接到按钮按下。 connect(...) 函数的文档可以在 here 找到。
基本上,每次在一组单选按钮中检测到更改时,都会调用作为指向connect(...) 函数的指针传递的函数。
下面是简短的sn-p代码:
...
_group = new Wt::WButtonGroup(this);
Wt::WRadioButton *button;
button = new Wt::WRadioButton("Radio Button 0", this);
_group->addButton(button, 0);
_group->setSelectedButtonIndex(0); // Select the first button by default.
_group->checkedChanged().connect(this, (&MyWidget::RadioButtonToggle)); //Need to pass parameter here
...
我需要将selection 参数传递给函数RadioButtonToggle(Wt::WRadioButton *selection),以便我可以在函数体中使用它,如下所示:
void CycleTimesWidget::RadioButtonToggle(Wt::WRadioButton *selection)
{
switch (_group->id(selection))
{
case 0:
{
//Do something...
break;
}
}
}
如何将参数与函数指针一起传递?
【问题讨论】:
-
您可能想查看functors。