PDA

View Full Version : MOC Error



Atomic_Sheep
19th September 2017, 15:06
Hi,

If I understand this correctly, the moc files that get generated when the project is built that basically add code that provides signals and slots functionality and probably other things.

I'm getting an error however which basically says that in one of these generated moc files,

"No such file or directory" for one of the .h files that is in my project structure. My files are all in the same folder including the .pro file so I don't think I need to add INCLUDEPATH in the .pro file. I'm not sure why the compiler isn't seeing it.

I've searched through other peoples problems with this but that hasn't helped :( everyone has different ways of solving these problems that don't apply in my case e.g. people switching from windows to ubuntu or simply deleting the build files and building a fresh project.

Any ideas where to look to solve this?

I've had issues with moc files before but never managed to fully understand how to solve them, would like to get over this bridge this time.

d_stranz
19th September 2017, 17:41
In Visual Studio, moc creates "moc_xyz.cpp" files into "GeneratedFiles/Debug" and "GeneratedFiles/Release" subdirectories of the main project directory. If you are using Qt Creator and doing an out-of-source build, probably a similar thing happens in the build directory. An include file error probably means that moc has not used a relative path when writing the code for the generated file, or the cpp compiler has not been configured with the right set of include paths.

Have you moved or renamed files sometime before this error occurred? Or changed the build location? Maybe manually running qmake again will fix things.

Atomic_Sheep
20th September 2017, 00:27
Yes doing an out of source build. It's the default as far as I know.

moc is using relative paths i.e. in my case:


"#include "../../Source Folder/MyHeader.h"

but that's the correct directory to find the header file!

No, haven't moved or renamed anything, freshly created class files and dropping the error right out of the box. I've barely written any code! Just compiling as I go and boom, error petty much with a Virgin file.

Nor have I changed the build location.

Of course, it compiles if I manually set the path of the header file in the moc file, but I would much rather figure out why it's generated incorrectly in the first place.

Atomic_Sheep
20th September 2017, 06:54
If I manually use an absolute path that is.

d_stranz
20th September 2017, 18:05
Sorry, can't help you much. I rarely use Qt Creator and use Visual Studio and/or CMake instead. Maybe someone more familiar with Qt Creator can offer a solution.