11

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?

3
  • Would you mind posting the droparea.h file that gives the error when being moc'ed?
    – Fred
    Aug 25, 2010 at 19:02
  • I can't actually post any of the source code unfortunately, the project is for work. However, the .h file is almost identical to the one found in the Drop Area example that comes with QT creator.
    – CoutPotato
    Aug 25, 2010 at 19:12
  • 1
    Additional note: this error can also occur when trying to use Q_OBJECT with template class. How to use signal/slot functionality in template class described in: stackoverflow.com/questions/4397478/qt-templated-q-object-class May 13, 2017 at 19:50

8 Answers 8

11

Click on "compile output", scroll up and click the red line.

In my case the Red line was saying: You cant define an integer value in private slots..

Under the qt creator window, in "progress details" section, there is a button named "compile output" (button number 4). Errors are explained there with red font. Click it and scroll up.

0
9

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.

1
  • I had that problem before. Can you accept your own answer? That will remove it from the unanswered list. Aug 28, 2010 at 2:39
6

This can be because of few other things as others have mentioned. I would like to add another one which is missing here.

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.

1
1

This can be because of many things I guess - I had a similar situation where I forgot to remove an entry in the .qrc file that didn't exist anymore.

So check your resource paths as well.

1

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.

1

Like J.Javan already pointed to, it might be helpful to check also the compiler output. In my case I found:

../stateMaschine/usermenu.h:57: Error: Class declarations lacks Q_OBJECT macro. make: *** [Makefile:215: moc_usermenu.cpp] Error 1

So this helped me to fix the error by correction of the class declaration when using signals and slots:

class Menu : public QObject{
    Q_OBJECT
    ...
0

Same Error 1 occured to me due to a ressource file (.qrc) which referred to a file name beginning with a period. When I removed the period from the file name, compilation worked again. Interestingly, the error only occured under Mac OSX using the Clang compiler. On Windows using the gcc compiler, the file name did not provoke an error.

Maybe the "[source file name] Error 1" message in general means that a file could not be found due to unexpected characters in the file path.

2
  • 1
    I think this should have been a comment and not an answer Apr 26, 2017 at 21:23
  • 1
    Right. But I wasn't allowed to comment (too low a score). But, again, this is a comment. I welcome my upgrade. Apr 27, 2017 at 22:35
-1

In my case, I ran out of space on SD card causing this sort of error.

Not the answer you're looking for? Browse other questions tagged or ask your own question.