I inherited a class from QObject :
class Parent: public QObject
{
Q_OBJECT
QObject* cl;
public:
Parent(QObject *parent=0):QObject(parent) {
I solved my problem by adding this to my header file :
#ifndef MYCLASSNAME_H
#define MYCLASSNAME_H
... // all the header file content.
#endif
I know that this is a very old question, but it seems to be still interesting (I've been here at least 4 or 5 times in the last months) and seems like I found another reason for which is possible to get this error.
In my case in the header file I wrongly typed:
#include "MyClass.h""
Only after inspecting the whole output I found out that at that line the compiler was emitting a warning.
Now that I removed the additional quotation mark my QObject compiles perfectly!
If you're using Visual Studio, delete the line Q_OBJECT
from the header file, save the file, put Q_OBJECT
back into the header file, save the file again. This should generate the moc_*
file and should build and link correctly.
So the issue was I needed the Qt MOC compiler to compile my .h file. This is required for any classes that extend QObject or one of its children. The fix involed (for me) right-clicking on the header file, choosing Properties, and setting the Item Type to "Qt MOC Input", then hitting "Compile" on the header, and then adding the resulting moc_myfilename.cpp file to my project.
For me, this is the cause: some header or source file not included in QT's project file
I have the same problem, my solution was the encoding( my file with "UTF16LE BOM" can't generate with moc.exe ) , y create another file with ASCII enconding and it work.
HxD HexEditor can help you to see the codification.