我正在尝试使用以下代码将上下文菜单添加到树中:
void MainWindow::FileTreeContextMenu(const QPoint& pos)
{
QPoint globalPos = ui->fileTree->viewport()->mapToGlobal(pos);
QMenu menu;
menu.addAction("New Group");
QAction* selectedItem = menu.exec(globalPos);
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->fileTree->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->fileTree,
SIGNAL(customContextMenuRequested(const QPoint&)),
this,
SLOT(FileTreeContextMenu(const QPoint&)));
}
但是,当我运行它时,我收到以下错误:
QObject::connect: No such slot MainWindow::FileTreeContextMenu(const QPoint&)
in ..\src\Fixer\mainwindow.cpp:23
QObject::connect: (sender name: 'fileTree')
QObject::connect: (receiver name: 'MainWindow')
我究竟做错了什么?