#include <QtGui/QWidget>#include <QtGui/QApplication>class TestWidget : public QWidget{ Q_OBJECTpublic: TestWidget(QWidget *parent = 0, Qt::WFlags flags = 0) : QWidget(parent, flags) { } ~TestWidget(){} };int main(int argc, char *argv[]){ QApplication a(argc, argv); TestWidget w; w.show(); return a.exec();}
main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall TestWidget::metaObject(void)const " (?metaObject@TestWidget@@UBEPBUQMetaObject@@XZ)1>main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall TestWidget::qt_metacast(char const *)" (?qt_metacast@TestWidget@@UAEPAXPBD@Z)1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall TestWidget::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@TestWidget@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
DOSmoc -o moc_main.cpp main.cpp
C++ (Qt)#include "moc_main.cpp"
DOSD:\WORK\PROJECTS\CPlusPlus\QT\Qt_training\TestWidget>moc -o moc_main.cpp main.cppmain.cpp(0): Note: No relevant classes found. No output generated.