43488

Qt connect “no such slot” when slot exists [duplicate]

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.

Recommend

  • Circular dependencies with headers. Using #ifndef and #define
  • Share QAxObject between two threads?
  • Qt: Undefined reference to 'vtable' [duplicate]
  • how to use Qt setWindowFilePath
  • Transitioning between menu screens with QStateMachine
  • How to remove the horizontal line in a QWizard with a stylesheet?
  • Digits after the decimal QTableView delegate
  • Is there a parser equivalent of 'fragment' marking in ANTLR4?
  • drawing random circles, storing their coorindates in an array
  • How to pass EC named curve list used by SSL_CTX?
  • How to read piped content in C?
  • Regarding starting the threads on a condition
  • Simple linked list-C
  • SQLite connection strategies
  • How to calculate the camera position from Vuforia GL matrix?
  • Checking if an array in C is symmetric
  • Reduction and collapse clauses in OMP have some confusing points
  • Appending Character to Character Array In C
  • OOP Javascript - Is “get property” method necessary?
  • GridView breaks while scrolling
  • copying resource to sdcard gives a damaged file in android
  • Database structure design with variable amounts of fields
  • how to adjust image in a panel in Java swing?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Problems to linebreak with an int in JLabel
  • How reduce the height of an mschart by breaking up the y-axis
  • output of program is not same as passed argument
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • sending/ receiving email in Java
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Cannot Parse HTML Data Using Android / JSOUP
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • JTable with a ScrollPane misbehaving
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • unknown Exception android
  • Sorting a 2D array using the second column C++
  • failed to connect to specific WiFi in android programmatically
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?