0

I am trying to compile a minimal Qt Console application with event loop and a custom class with inline definition of its constructor like https://stackoverflow.com/a/4182144/1619432 and get three cryptic linker errors (using Qt 4.8.1 and MSVC 2010 Express C++):

main.obj:-1: error: LNK2001: Unresolved external symbol ""public: virtual struct QMetaObject const * __thiscall ....

with ::metaObject, ::qt_metacast, ::qt_metacall.

Community
  • 1
  • 1
handle
  • 5,859
  • 3
  • 54
  • 82

1 Answers1

0
#include "main.moc"

just above the int main(...) is critical. If the file is not found, try cleaning the project / deleting the build directories, running qmake, restarting Qt Creator or even the whole system. This may have to do with paths in environment variables (maybe set previously by a different project).

Another common reason seems to be a forgotten Q_OBJECT macro in the class declaration, or as above, run qmake after including it.

Good luck!

handle
  • 5,859
  • 3
  • 54
  • 82