Изучаю события, вот играясь наткнулся на ошибку, которая происходит если раскомменитровать //Q_OBJECT
#include <QApplication>
#include <QtGui>
class CSpyLineEdit : virtual public QLineEdit
{
//Q_OBJECT
public:
CSpyLineEdit(QWidget *parent = 0):QLineEdit(parent){}
protected:
void keyPressEvent(QKeyEvent *pKeyEvent)
{
if (pKeyEvent->key()==Qt::Key_0 && pKeyEvent->modifiers()==Qt::AltModifier)
{
this->setText("Clear complete");
}
else
{
QLineEdit::keyPressEvent(pKeyEvent);
}
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget wgt;
QVBoxLayout *pVboxLayout = new QVBoxLayout();
CSpyLineEdit *pSpyLineEdit = new CSpyLineEdit();
pSpyLineEdit->setMinimumSize(QSize(200,100));
pVboxLayout->addWidget(pSpyLineEdit);
pVboxLayout->setMargin(20);
wgt.setLayout(pVboxLayout);
wgt.show();
return app.exec();
}
//Compile output
mingw32-make: Leaving directory `D:/QT/MyModel/MyModel'
debug/main.o: In function `CSpyLineEdit':
D:\QT\MyModel\MyModel/../main.cpp:11: undefined reference to `vtable for CSpyLineEdit'
D:\QT\MyModel\MyModel/../main.cpp:11: undefined reference to `vtable for CSpyLineEdit'
D:\QT\MyModel\MyModel/../main.cpp:11: undefined reference to `vtable for CSpyLineEdit'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\MyModel.exe] Error 1
mingw32-make: *** [debug] Error 2
Exited with code 2.
Error while building project MyModel
When executing build step 'Make'
Build issues:
D:\QT\MyModel\MyModel/../main.cpp:11: undefined reference to `vtable for CSpyLineEdit'
:-1: error: collect2: ld returned 1 exit status