43488
![Qt connect “no such slot” when slot exists [duplicate]](https://www.xszz.org/skin/wt/rpic/t16.jpg)
Question:
This question already has an answer here:
<ul><li> <a href="/questions/1368584/what-does-the-q-object-macro-do-why-do-all-qt-objects-need-this-macro" dir="ltr" rel="nofollow">What does the Q_OBJECT macro do? Why do all Qt objects need this macro?</a> <span class="question-originals-answer-count"> 5 answers </span> </li> </ul>I am trying to connect a signal to a slot. The project compiles fine, but at runtime I get this error:
QObject::connect: No such slot QHeaderView::onFilterAdded(int)
here is my code:
class MySortFilterProxyModel: public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit MySortFilterProxyModel(QObject *parent = 0);
~MySortFilterProxyModel();
void addFilter(int col, SteFilter *pFilter);
void removeFilter(int col);
signals:
void filterAdded(int);
void filterRemoved(int);
}
class MyHeaderView: public QHeaderView
{
public:
MyHeaderView();
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
public slots:
void onFilterAdded(int);
void onFilterRemoved(int);
private:
QList<int> m_listFilters;
};
I use this line of code to connect the signal to the slot:
QObject::connect(&m_proxyModel, SIGNAL(filterAdded(int)), &m_headerView, SLOT(onFilterAdded(int)));
m_proxyModel is of type MySortFilterProxyModel and m_headerView is of type MyHeaderView. They are not pointers.
I don't get why this happens. I have connected other signals and slots using the same technique and had no problems. Any help would be appreciated, thanks.
Answer1:The class <em>MyHeaderView</em> doesn't have Q_OBJECT macro, don't forget to <em>run qmake</em> after you add it and only after that build your project.