Qt: LNK2001 and LNK2019 Errors occur after implementing a signal / slot in the source files

This consists of declarations in my MainWindow file, I did not include library inclusion for short. I have included QObject.h in both and all the required libraries. It compiles before turning on the second connection 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 looked for these error messages, most of the solutions provided revolved around fixing the make command / path or something like what happens when compiling in Visual Studio.

I repeat, these errors appeared ONLY after turning on this second call to connect the global GCamera and MainWindow. The program was compiled and executed before that.

Thank you in advance, I apologize for the long post and look forward to receiving any data.

+4
source share
2 answers

You should have a file called moc_tcamera.cpp that implements the missing character in the assembly directory.

If this is not the case, you should โ€œrun qmakeโ€ and โ€œRestoreโ€ your project (both actions are in the Qt Creator Build menu).

Why the error occurred:

qmake adds moc (Qt meta object compiler) to the Makefile for all source files containing Q_OBJECT or Q_GADGET , such a file is called "mocable". After a file is detected as mosaic or unfocused, this status does not change until qmake is restarted.

QtCreator starts qmake on its own when a .pro file changes (for example, when adding or removing a file).

This means that you probably compiled the project once without the Q_OBJECT macro in the Q_OBJECT file and then added this macro. And since you do not need a meta object until you add a call to connect , VC ++ has not tried to resolve missing characters.

+5
source

You may get linker errors if you, say, include a header in your .pro file, but not the source. For example, in a .pro file:

 HEADERS += t_camera.h foo.h SOURCES += foo.cpp 

will result in linker errors, usually LNK2001 and LNK2019. However, IIRC QtCreator manages .pro files for you, right? In other words, make sure your .pro file is correct. I would be surprised if this were not the case, but errors in the .pro file may cause the problem you are seeing.

+1
source

Source: https://habr.com/ru/post/1411663/


All Articles