Try to emit signal in keyPressEvent
-
Hi. Why do I have errors? What is my mistake?
The first in constructor: undefined reference to `vtable for LineEditClickedButton;
And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed#include <QLineEdit> class LineEditClickedButton : public QLineEdit { Q_OBJECT public: explicit LineEditClickedButton(QWidget *parent = nullptr); protected: void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; signals: void buttonPressed(QString button); };#include "lineeditclickedbutton.h" #include <QKeyEvent> LineEditClickedButton::LineEditClickedButton(QWidget *parent) : QLineEdit(parent) {} void LineEditClickedButton::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Escape: emit buttonPressed("esc"); break; case Qt::Key_Tab: emit buttonPressed("tab"); break; } QLineEdit::keyPressEvent(e); } -
Hi. Why do I have errors? What is my mistake?
The first in constructor: undefined reference to `vtable for LineEditClickedButton;
And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed#include <QLineEdit> class LineEditClickedButton : public QLineEdit { Q_OBJECT public: explicit LineEditClickedButton(QWidget *parent = nullptr); protected: void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; signals: void buttonPressed(QString button); };#include "lineeditclickedbutton.h" #include <QKeyEvent> LineEditClickedButton::LineEditClickedButton(QWidget *parent) : QLineEdit(parent) {} void LineEditClickedButton::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Escape: emit buttonPressed("esc"); break; case Qt::Key_Tab: emit buttonPressed("tab"); break; } QLineEdit::keyPressEvent(e); }@Evgeny-Siberia
Since I can't spot anything: have you cleaned out all intermeditae files in the compilation output directory and rebuilt? Especially if you have recently added theQ_OBJECT. At least make sure the error remains. -
Hi. Why do I have errors? What is my mistake?
The first in constructor: undefined reference to `vtable for LineEditClickedButton;
And others in keyPressEvent: undefined reference to LineEditClickedButton::buttonPressed#include <QLineEdit> class LineEditClickedButton : public QLineEdit { Q_OBJECT public: explicit LineEditClickedButton(QWidget *parent = nullptr); protected: void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; signals: void buttonPressed(QString button); };#include "lineeditclickedbutton.h" #include <QKeyEvent> LineEditClickedButton::LineEditClickedButton(QWidget *parent) : QLineEdit(parent) {} void LineEditClickedButton::keyPressEvent(QKeyEvent *e) { switch (e->key()) { case Qt::Key_Escape: emit buttonPressed("esc"); break; case Qt::Key_Tab: emit buttonPressed("tab"); break; } QLineEdit::keyPressEvent(e); }