Menu菜单 或 其中的QAction 连接槽函数
以下两句connect 任一均可实现:
QStringList strList;
for(int i = 0; i< strList.size(); ++i)
{
QString tmp = strList.at(i);
QAction *act = new QAction(tmp, m_menu);
act->setCheckable(true);
act->setChecked(false);
m_menu->addAction(act);
connect(act, SIGNAL(triggered()), this, SLOT(checkedAction()));
}
//connect(m_menu, SIGNAL(triggered(QAction*)), this, SLOT(checkedLibAction(QAction*)));
QSignalMapper
signalMapper = new QSignalMapper(this);
for (int i = 0; i < texts.size(); ++i) {
QPushButton *button = new QPushButton(texts[i]);
connect(button, SIGNAL(clicked()), signalMapper, SLOT(map()));
signalMapper->setMapping(button, texts[i]);
}
connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(clicked(QString)));