Note that there are some explanatory texts on larger screens.

plurals
  1. POdetecting header click in QTableWidget c++ qt4
    text
    copied!<p>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 <a href="https://stackoverflow.com/questions/4128539/qt-c-qtablewidget-doing-something-when-a-header-is-doubleclicked">here</a> </p> <p>Compile Error:</p> <pre><code>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 </code></pre> <p>My Code:</p> <pre><code>QObject::connect(ui-&gt;table_results-&gt;horizontalHeader(),SIGNAL(sectionDoubleClicked(int)), this,SLOT(hheaderclicked(int))); </code></pre> <p>Edit: I was able to get my code to work by doing the following: </p> <pre><code>QObject::connect((QObject*)ui-&gt;table_results-&gt;verticalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(hheaderclicked(int))); </code></pre> <p>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:</p> <pre><code>QObject::connect(ui-&gt;button_start,SIGNAL(clicked()),this,SLOT(scanstart())); </code></pre> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload