Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt moc error 1 - what does it mean?

Tags:

qt

qt-creator

I'm trying to build a project on Mac OSX, and it's giving me a cryptic error:

[moc_droparea.cpp] Error 1

droparea.cpp is (obviously) a file in the project. I checked that it exists in the project directory and is not corrupted. The file moc_droparea.cpp doesn't show up in the build folder after this error, so I'm assuming it's failing to build for whatever reason, but the error is too vague to help me figure out what's going on. Could anyone help me figure out what this means please?

like image 870
CoutPotato Avatar asked Aug 25 '10 18:08

CoutPotato


People also ask

What is MOC in Qt?

Qt's moc (Meta Object Compiler) provides a clean way to go beyond the compiled language's facilities. It does so by generating additional C++ code which can be compiled by any standard C++ compiler. The moc reads C++ source files.

How to fix MOC error 1?

You will get a "moc error 1" in case you create a class and add Q_OBJECT to it but do not inherit from QObject. If you take a look at Compile Output there is a line saying: Error: Class contains Q_OBJECT macro but does not inherit from QObject Hence, the general approach to fix this problem is just taking a look at "Compile Output" window.

How does the MOC read C++ source files?

The moc reads C++ source files. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces another C++ source file which contains the meta object code for those classes.

How to fix error 1 in QRC?

You can right click on the error 1 and select 'View output'. In my case, I had a bad file name in my qrc file. Show activity on this post. Like J.Javan already pointed to, it might be helpful to check also the compiler output. In my case I found: So this helped me to fix the error by correction of the class declaration when using signals and slots:


1 Answers

The solution was annoyingly simple. I had a folder structure that put spaces (illegal characters) in the file path. I put underscores instead of spaces and it built fine. I would think the moc pre-processor could handle spaces in file names, but apparently not. I feel foolish, but at least the problem is solved now.

Hopefully this solution can help someone else.

like image 167
CoutPotato Avatar answered Nov 13 '22 00:11

CoutPotato