Qt moc error 1 - what does it mean? - qt

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?

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.

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.

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.

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.

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.

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
...

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.

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

Related

What does [Inexact] in the console mean when running qmake?

In my Qt5 project I have the following log statement in a .pri file that is included multiple times in a for-in-loop by my main .pro file (Qt5 qmake):
message("== INC: $$lo)")
For most values of $$lo it print the following (expected) string:
Project MESSAGE: == INC: myValue)
But for some cases, a [Inexact] is prepended so that it instead looks like this:
[Inexact] Project MESSAGE: == INC: myValue)
What does that mean? Should I care? How could I get rid of it (it's kind of annoying).
TL;DR: The [Inexact] prefix is added by Qt Creator IDE, and is of no consequence as to the correctness of the .pro files.
It doesn't mean that there's anything wrong with your project file, but merely that Qt Creator can't figure out where this message originated. It means that it could come from a file other than the one indicated/assumed. It seems to be there to prevent you from going off on a wild goose chase on a message that doesn't really originate in the .pro file you think.
See ProMessageHandler::ProMessageHandler.

Fatal error: UnCSS: could not open

I'm trying to remove all of the unused css in the framework I'm using by using uncss. But when I try I get the error:
file:///C:/Users/Angus/Desktop/FTTL%20website%20submit/index.html:15 in onload
Fatal error: UnCSS: could not open C:\Users\Angus\Desktop\FTTL website%20submit\css\main.css
Does anyone know why this is?
Iyou forget to handle the first space properly (FTTL website%20submit) in the path, if you change the folder name or escape it properly (like FTTL%20website%20submit) it might work.
Edit: Or the other way around and the %20 substitution for the path was not working for the second space. (I am not familiar with uncss.)
(In my opinion it is best not using spaces in file and folder names.)

Ada compilation "does not contain expected unit"

I have a program that is written in Ada, and I need to compile it. When I do so, I get a "does not contain expected unit" error, and it says it is expecting a spec but found a body. I need it compile it, and I don't know about Ada. I am using the gnat compiler. and i cant put any code up but i can say that it is a adb file with other ads files in the folder.
The error :
"does not contain expected unit"
usually occurs when the name of the unit does not match the file name (package body aaa.bbb needs to be in file aaa-bbb.adb and package aaa.bbb needs to be in aaa-bbb.ads)
"expecting a spec but found a body"
probably means you have a mismatch between the contents of the file and the file extension (ads or adb)
Beyond this i can only upvote the comment by Marc C

Qt - moc causing C2504: base class undefined

I'm having a problem that I've been trying to solve for a while, but I am completely stumped. So I have two classes, X and Y, and they each have their own header files, X.h and Y.h. Each is a Q_OBJECT and has that macro definition in the header file.
class Y: public X { Q_OBJECT ...}
The definition of Y reads. The definition of X reads:
class X: public QGLWidget {Q_OBJECT ...}
When I compile, X.cpp and Y.cpp compile correctly and there are no problems at that stage. The moc files are also generated with no problem.
However, when the standard QT build process goes to compile moc_X.cpp, it gives me "C:\path\Y.h(34) : error C2504: 'X' : base class undefined". But this doesn't happen when it's compiling Y.cpp or X.cpp, it only happens when it's compiling the moc files! Any ideas? That the build would be failing at the moc stage and only moc stage seems extremely peculiar. Help is much appreciated!
I've tried reproducing it, with the description you give, and haven't been able to.
So, here are things that would be worth checking:
errors in include guards?
Check that you haven't accidentally got 2 include-guards of the same name in 2 different headers (i.e. the #ifndef X_H and #define X_H lines)
(This is perhaps less likely, from your description: it would be more likely if the error was in the compiling of moc_Y.cpp)
forward declarations for types used in signals or slots?
Sometimes a parameter in a signal or slot can require an extra header to be included.
The best way I can explain it is to say that there are cases where your header would be fine with a forward-declaration to a class, but the moc can generate code that needs to actually create or destroy a type that your header only forward-declares.
If this is the case, there is a way to add code to the .ui, that requests inclusion of the extra header for the forward-declared type. But the easiest solution is just to replace the forward declaration with the appropriate header instead, inside X.h or Y.h.
check the contents of the moc_X.cpp file
If the above doesn't help, and if you haven't done so already, I'd suggest opening up the offending moc file and reading the code. Once you see what it's doing, it might give you some ideas.

including Qt headers in DLL

I have a DLL in wich I would like to take a reference to a QObject and manipulate it, without actually creating an interface. So, I included "Qt/qobject.h" and compiled, but the compiler (Visual Studio 2008 pro) gives me syntax errors. It looks like it doesn't recognize the QThread object. How do I use a QObject in my dll? Is this even possible? Do I have to start my program from a Qt app? I'm actually trying to set a system-wide hook and get 3rd application QWidgets to manipulate... Any idea how I can use QObject in my dll?
Here are the errors:
1>------ Build started: Project: FroggerDLL, Configuration: Debug Win32 ------
1>Compiling...
1>FTClient.cpp
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2059: syntax error : 'type'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(154) : error C2238: unexpected token(s) preceding ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2059: syntax error : ')'
1>c:\qt-win-opensource-src-4.5.2\src\corelib\kernel\qobject.h(155) : error C2208: 'int' : no members defined using this type
1>FroggerDLL - 6 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 3 up-to-date, 0 skipped ==========
Any help would be greatly appreciated,
Thanks
Dave
What's on line 154? Mine is just the declaration
QThread* thread() const;
but that's 4.5.1 on Linux so it might be different. The first reference to anything involving the token type is on line 204 which is a variable of type Qt::ConnectionType.
BTW. I just tried compiling the following on my system ( in the file incqobj.cpp )
include <QOObject>
QObject myQOject;
with
g++ -I/usr/lib/qt4/include -I/usr/lib/qt4/include/QtCore -c incqobj.cpp
and it compiled fine so it should be as simple as that.
Edit: Since Jesse confirms that it works for him on Windows I'm tempted to say that you've got a non-Qt macro coming in and interfering. One thing you could do is a sanity check on what the compiler is actually seeing by getting VS to only produce the preprocessed source rather than do the compilation.
I haven't used VS in years but I think the option is \E maybe?
[Edit: see the 2nd comment by Jesse, it should be /E] It may also be an explicit option now in the compiler properties which can be set for that source file. Can't remember where it puts the output either so you may need to hunt around for it a bit! If you get that going though you can check to see if the code looks right at the part that would correspond to line 154 in the original QObject header.
Thanks for all the help, solution: I had to include the Qt headers before all my other includes, and it now compiles.
Thanks again!
Try including QThread?
#include <QThread>
Qt uses forward declaration extensively and sometimes you need to include extra headers.
EDIT:
Do you set any defines? Here is what I have for my 2003 Qt commercial (4.3.4) project (executable that links to Qt dlls):
QT_LARGEFILE_SUPPORT
QT_DLL
QT_GUI_LIB
QT_CORE_LIB
QT_THREAD_SUPPORT
QT_NETWORK_LIB

Resources