Qt: LNK2001 and LNK2019 Errors arise after implementing a signal/slot across source files

c++, linker, qt, qt-creator

Solution

You should have a file named `moc_tcamera.cpp` that implements the missing symbol in the build directory.

If it isn't present, you should "run qmake", and "Rebuild" your project (both actions are in Qt Creator Build menu).

Why the error occured:

qmake adds a moc (Qt's meta object compiler) step to the Makefile for all the source files that contains the macros `Q_OBJECT` or `Q_GADGET`, such file is said to be "mocable". Once a file is detected as mocable or non mocable, that status doesn't change until qmake is rerun.

QtCreator only runs qmake by itself when the .pro file changes (for example, when you add or remove a file).

It means you probably compiled the project once without the `Q_OBJECT` macro in the file `tcamera.h`, and added that macro afterward. And because you didn't need the meta object until you added the call to `connect`, VC++ didn't try to resolve the missing symbols.

Problem

This consists of the declarations in my MainWindow file, I haven't included the library inclusions for brevity. I have included QObject.h in both, and all required libraries. It was compiling fine before the inclusion of the second connect call. The first Ctrl-C handler works fine. `I took out my code, thought my employer wouldn't like it. See the appropriate response below!` I am using QT Creator. When I googled these error messages, most of the solutions provided revolved around fixing the make command/path or something of the sort which occurs when compiled in Visual Studio. I reiterate, these errors showed up ONLY after the inclusion of that second connect call of the global GCamera and the MainWindow. The program was compiling and running before this. Thank you in advance, I apologize for the lengthy post and look forward to receiving any input.

Original source