2

我在连接自定义菜单时遇到问题,QListWidget连接函数返回 false。这是代码:

我有一些名为MainWindow. 在它的构造函数中我有这条线

connect(ui->notesWidget, SIGNAL(customContextMenuRequested(QPoint &)), 
        this, SLOT(contextMenuforNotesArea(QPoint &)));

在哪里notesWidget提到QListWidget

ContextMenuforNotesArea(QPoint &)是这样定义的

class MainWindow : public QMainWindow
{
public slots:
    void contextMenuforNotesArea(QPoint &pos);
};

void MainWindow::contextMenuforNotesArea(const QPoint &pos){
    QMessageBox::information(this, "a", "the function has been finally called");
    QMenu contextMenu(tr("Context menu"), this);
    contextMenu.addAction(new QAction(tr("Hello"), this));
    contextMenu.exec(mapToGlobal(pos));
}

我还通过表单设计器更改contextMenulistWidgetto中的属性。customContextMenu

4

1 回答 1

0

在头文件中按如下方式更改您的 SLOT 签名

void contextMenuforNotesArea(const QPoint &pos);

还要确保,当您在构造函数中进行连接时,您在调用setupUi

于 2012-11-21T11:28:30.990 回答