I tried to write a simple Qt application as follows:
main.cpp:
#include <QApplication> class MyApp : public QApplication { Q_OBJECT public: MyApp(int argc, char* argv[]); }; MyApp::MyApp(int argc, char* argv[]) : QApplication(argc,argv) { } int main(int argc, char* argv[]) { MyApp app(argc,argv); return app.exec(); }
But when I tried to compile and link it with Qt Creator 2.3.1 (Qt 4.7.4), I get 3 errors of unresolved external characters:
main.obj: -1: error: LNK2001: unresolved external character
"public: virtual struct QMetaObject const * __thiscall MyApp :: metaObject (void) const"
(? Metaobject @MyApp @@ UBEPBUQMetaObject @@ XZ). "
main.obj: -1: error: LNK2001: unresolved external character
"public: virtual void * __thiscall MyApp :: qt_metacast (char const *)"
(? Qt_metacast @MyApp @@ UAEPAXPBD @Z). "
main.obj: -1: error: LNK2001: unresolved external character
"public: virtual int __thiscall MyApp :: qt_metacall (enumeration QMetaObject :: Call, int, void * *)"
(? Qt_metacall @MyApp @@ UAEHW4Call @QMetaObject @@ HPAPAX @Z). "
I think they are somehow related to the MetaObjectCompiler Qt, but I cannot find a solution. I know that this is not considered a good programming style in C ++ to put declarations and definitions in a single file, but it is not. In my opinion, this should be possible, since there is nothing syntactically wrong here.
source share