[Interest] How to pass parameter from Menu/Action to SLOT()
Nicholas Yue
yue.nicholas at gmail.com
Tue Jan 5 21:58:52 CET 2021
Hi,
I am programmatically generating a menu, each menu item has a unique
name/label
How can I determine which of the generated menu was clicked ?
```
void MainWindow::init()
{
:
:
QMenu *specialists = menuBar()->addMenu("&Specialists");
if (!_engine.getSpecialistsManager().registeredSpecialists().empty()){
std::vector<QAction*>
specialistMenuAction(_engine.getSpecialistsManager().registeredSpecialists().size());
size_t specialistMenuActionIndex = 0;
for (auto iter =
_engine.getSpecialistsManager().registeredSpecialists().begin();
iter != _engine.getSpecialistsManager().registeredSpecialists().end();
++iter,specialistMenuActionIndex++)
{
specialistMenuAction[specialistMenuActionIndex] = new
QAction((boost::format("&%1%")%(iter->first)).str().c_str(), this);
specialists->addAction(specialistMenuAction[specialistMenuActionIndex]);
connect(specialistMenuAction[specialistMenuActionIndex],
SIGNAL(triggered()), this, SLOT(specialistMenuHandler()));
}
}
:
:
}
```
```
void MainWindow::specialistMenuHandler()
{
std::cout << "MainWindow::specialistMenuHandler()" << std::endl;
}
```
Cheers
--
Nicholas Yue
Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
Custom Dev - C++ porting, OSX, Linux, Windows
http://au.linkedin.com/in/nicholasyue
https://vimeo.com/channels/naiadtools
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210105/59e63f2c/attachment.html>
More information about the Interest
mailing list