Qt:找不到QTableWidget :: cellClicked信号/插槽的问题

时间:2018-09-24 08:49:45

标签: c++ qt signals-slots qtablewidget

我有一个QTableWidget,如果单击一个单元格,我想向MainWindow发出信号。

我的头文件:

QTableWidget *myQtableWidget= new QTableWidget;
...
private slots:
    void on_myTableWidgetWindow_cellClicked(int row, int column);

mainWindow.cpp(在mainWindow的构造函数中):

connect(this->myQtableWidget, SIGNAL(cellClicked(int row, int column)),
        this, SLOT(on_myTableWidgetWindow_cellClicked(int row, int column)));

mainWindow.cpp(某处):

void mainWindow::on_myTableWidgetWindow_cellClicked(int row, int column)
{
//do something
}

控制台输出为:

QMetaObject::connectSlotsByName: No matching signal for on_myTableWidgetWindow_cellClicked(int,int)
QObject::connect: No such signal QTableWidget::cellClicked(int row, int column) in ..\myProg\windowMain.cpp:71
QObject::connect:  (receiver name: 'mainWindow')

为什么控制台告诉我:“没有这样的信号QTableWidget :: cellClicked”? 在QT文档中,该信号被列出:http://doc.qt.io/qt-5/qtablewidget.html#cellClicked

我看不到自己的错误,有人可以帮忙吗? 最好,

1 个答案:

答案 0 :(得分:0)

显然,您可以简单地摆脱“行”和“列”。我的意思是:

connect(this->myQtableWidget, SIGNAL(cellClicked(int, int)), 
        this, SLOT(on_myTableWidgetWindow_cellClicked(int, int)));