Error: no matching member function for call to 'connect'
Solved
General and Desktop
-
Hi,
How to solve the error
error: no matching member function for call to 'connect'
in the example:#include <QApplication> #include <QWidget> #include <QTimer> #include <QDebug> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr) : QWidget(parent) { connect(m_timer, &QTimer::timeout, this, &Widget::printMessage); } private slots: void printMessage() { qDebug() << "timer"; } private: QTimer m_timer; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); }
-
@8Observer8 your m_timer is on the stack therefore
connect(&m_timer, &QTimer::timeout, this, &Widget::printMessage);
-
Thank you very much! But now I have another error in the example above: https://forum.qt.io/topic/117951/error-undefined-reference-to-vtable-for-widget