<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<pre style="margin-top: 0px; margin-bottom: 0px;" class="">in your handler you can call this:<br class=""><blockquote type="cite" class="">QAction<span style=" color:#c0c0c0;" class=""> </span>*actionP(qobject_cast<QAction<span style=" color:#c0c0c0;" class=""> </span>*>(QObject::sender()));</blockquote></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""><!--EndFragment--></pre><div class="">and you'll get the action that caused the sending.</div><div class="">you can have previously stuffed something interesting into the objectName of the action, then recover it in your handler</div><div class=""><br class=""></div><div class="">does that make sense?</div><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 5, 2021, at 12:58 PM, Nicholas Yue <<a href="mailto:yue.nicholas@gmail.com" class="">yue.nicholas@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi,<div class=""><br class=""></div><div class=""> I am programmatically generating a menu, each menu item has a unique name/label</div><div class=""><br class=""></div><div class=""> How can I determine which of the generated menu was clicked ?</div><div class=""><br class=""></div><div class="">```</div><div class=""><font face="monospace" class="">void MainWindow::init()<br class="">{<br class=""> :<br class=""> :<br class=""> QMenu *specialists = menuBar()->addMenu("&Specialists");<br class=""> if (!_engine.getSpecialistsManager().registeredSpecialists().empty()){<br class=""><br class=""> std::vector<QAction*> specialistMenuAction(_engine.getSpecialistsManager().registeredSpecialists().size());<br class=""><br class=""> size_t specialistMenuActionIndex = 0;<br class=""> for (auto iter = _engine.getSpecialistsManager().registeredSpecialists().begin();<br class=""> iter != _engine.getSpecialistsManager().registeredSpecialists().end();<br class=""> ++iter,specialistMenuActionIndex++)<br class=""> {<br class=""> specialistMenuAction[specialistMenuActionIndex] = new QAction((boost::format("&%1%")%(iter->first)).str().c_str(), this);<br class=""> specialists->addAction(specialistMenuAction[specialistMenuActionIndex]);<br class=""> connect(specialistMenuAction[specialistMenuActionIndex], SIGNAL(triggered()), this, SLOT(specialistMenuHandler()));<br class=""> }<br class=""> }<br class=""> :<br class=""> :<br class="">}</font><br class="">```</div><div class=""><br class="">```</div><div class=""><font face="monospace" class="">void MainWindow::specialistMenuHandler()<br class="">{<br class=""> std::cout << "MainWindow::specialistMenuHandler()" << std::endl;<br class="">}<br class=""></font></div><div class="">```</div><div class=""><br class=""></div><div class="">Cheers<br clear="all" class=""><div class="">-- <br class=""></div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class="">Nicholas Yue<br class=""></div></div></div></div></div></blockquote></div><br class=""></body></html>