I have a QTableWidget in my program that I use to display results and I am trying to be able to detect when a user single clicks one of the vertical headers. To do this I am trying to connect the signal sectionDoubleClicked(int) to my function hheaderclicked(int). When I try to compile the code I get a compile time error about no matching function. I am basing my code from the post here
Compile Error:
mainwindow.cpp:138: error: no matching function for call to âMainWindow::connect(QHeaderView*, const char [27], MainWindow* const, const char [21])â
/usr/lib64/qt4/include/QtCore/qobject.h:181: note: candidates are: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)
/usr/lib64/qt4/include/QtCore/qobject.h:282: note: bool QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const
My Code:
QObject::connect(ui->table_results->horizontalHeader(),SIGNAL(sectionDoubleClicked(int)),
this,SLOT(hheaderclicked(int)));
Edit: I was able to get my code to work by doing the following:
QObject::connect((QObject*)ui->table_results->verticalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(hheaderclicked(int)));
Can some one explain why I had to cast QHeaderView* to QObject* to get this to work, i don't have to cast any of my other QObject::connect calls and they all work fine. For example this work fine:
QObject::connect(ui->button_start,SIGNAL(clicked()),this,SLOT(scanstart()));
is it because this one is connecting to a known object at compile time while my other one is connecting to a object that won't be known till runtime?
The error message gives the third argument as MainWindow* const
, which is rather odd. If it was const MainWindow*
, the call should work. How is the calling function declared?