Solved class with q_object macro declared and defined in .cpp
-
i know that one can't have a nested class which has Q_OBJECT macro defined in it, in a class (even though i don't quite well understand the reasons, if someone explained i'd be very happy)
but my question here is about something else. as i can't have a nested (private) class, i'd like to place that clasa in .cpp file, as the title suggests, which i did and got "undefined reference for vtable" error, while my class had a virtual dtor (it's derived from QWidget). but when i place the class in .h file, it works fine. what's the reason for this?
-
Hi,
You are missing the moc file inclusion at the bottom of the your code.
-
The reason is:
The moc tool that uses the Q_OBJECT and generate mappings for signals and slot are run on .h files only. -
so how can i "hide" this class? it's something like this:
class A : public QWidget {/* definition */}; class B : public QWidget { A *a; // other members // other functions };
of course i wanna "hide" class A
-
@user4592357
Hi
You can use the .cpp file as @SGaist suggests. -