我一直在尝试将QSignalMapper与Qt 4.8一起使用。但我无法从信号映射器获取信号。我的代码与qt在其网站上的代码类似。我的mySlot函数应该接收值并执行,但点击按钮没有任何反应。
vector<QPushButton *> button;
QSignalMapper *signalMapper;
signalMapper = new QSignalMapper(this);
for (int i = 0; i<10; i++)
{
button.push_back(new QPushButton(“myButton”);
QObject::connect(button[i], SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button[i], i);
}
QObject::connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(mySlot(int)));
void class::mySlot(int position)
{
QMessageBox msgBox;
msgBox.setText(QString(“Button #: %1”).arg(position));
msgBox.exec();
}