Undefined reference to staticMetaObject
-
Hello, I receive errors about
Undefined reference to staticMetaObject
when I have a class that is derived from a parent class which inherits QObject. I am wondering why is it? -
@Christina123 said in Undefined reference to staticMetaObject:
I receive errors about
Undefined reference to staticMetaObject
"Undefined reference" means that you have something that is declared but not defined. See https://www.cprogramming.com/declare_vs_define.html
I am wondering why is it?
staticMetaObject
is declared by theQ_OBJECT
macro. It is then defined in themoc_*.cpp
file that is auto-generated by moc.So, your error means that your class has the
Q_OBJECT
macro but it was not processed by moc. Check 2 things:- By default, moc expects you to define QObject subclasses in *.h files rather than *.cpp files. If your class in in a *.cpp file, move it to a *.h file.
- If you have done this but still get the error, you can force moc to run by running qmake.
-
@VRonin said in Undefined reference to staticMetaObject:
I think the question is, are you using CMake or qmake?
Ah yes, that's an important point!
-
@david-azolai said in Undefined reference to staticMetaObject:
I have the same problem and use CMake , what can I do?
Show your CMakeLists.txt and describe exactly what you're doing / trying to do.