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?
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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With