简体   繁体   中英

Problem with QSignalMapper and QAction never triger the Slot

Hi i try to bind slot with argument to QAction triggered SIGNAL i have this code,the context menu working great. BUT the OpenPublishWin never triggered.

void MyApp::ShowContextMenu(const QPoint& pos) // this is a slot
{
    QString groupID;
    QPoint globalPos = ui.treeView_mainwindow->mapToGlobal(pos);
    QModelIndex modelIndx = ui.treeView_mainwindow->indexAt(pos);
    groupID = modelIndx.model()->index(modelIndx.row(),0,modelIndx.parent()).data(Qt::UserRole).toString();
 QMenu myMenu;
  OpenPublishAction = new QAction(tr("Send"), this);
 myMenu.addAction(OpenPublishAction);

 connect(OpenPublishAction, SIGNAL(triggered()),m_SignalMapper, SLOT(map()) );
 m_SignalMapper->setMapping(OpenPublishAction,groupID);
 connect(m_SignalMapper, SIGNAL(mapped(QString)), this, SLOT(OpenPublishWin(QString)));

    QAction* selectedItem = myMenu.exec(globalPos);

}
void MyApp::OpenPublishWin(QString gid)
{
 WRITELOG(gid)
}

A quick look at the Qt docs for QSignalMapper (assuming that is what you're using based on the question title) states that the parameter for the mapped signal is const QString&. I can't recall if the parameter needs to be exact in this case for the connection but it may be a factor.

Additionally, double check that your connects are being made by wrapping them in an assert or some form of verify. Qt will also print out to the console if a connection cannot be made.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM