【发布时间】:2011-05-20 08:21:47
【问题描述】:
我想在我的 QTableView 中的单元格上有一个上下文菜单,所以我首先连接:
connect(ui->tblTimesheet,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(sheetContextMenu(const QPoint &)));
该连接的插槽如下:
void wndMyWindow::sheetContextMenu(const QPoint &pos){
QMenu *menu = new QMenu;
QModelIndex cell = ui->tblTimesheet->indexAt(pos);
// Make sure the right click occured on a cell!
if(cell.isValid()){
QString myid=cell.sibling(cell.row(),0).data().toString();
menu->addAction("Remove item", this, SLOT(sheetRemoveItem()));
menu->exec(ui->tblTimesheet->mapToGlobal(pos));
}
}
它创建菜单并在菜单中放置一个操作,当单击该操作时调用一个函数。但是,我想通过变量 myid 进入第二个插槽。下面列出了该插槽:
void wndMyWindow::sheetRemoveItem(){
qDebug("Sure I'm here, but what info do I have?");
return;
}
我不太清楚该怎么做,有人可以帮忙吗?
【问题讨论】:
标签: c++ qt signals argument-passing