Friday, May 30, 2014

Tips and Tricks: Declaring and defining a QObject-derived class

Hello!

The tip of the day is the following:

If you're creating a class that inherits QObject (and therefore uses the Q_OBJECT macro), defining it on the .cpp file will not work. All classes that has such macro needs to be defined in a header file.
So being the case, here comes a tip: if your "main" class requires some secondary classes (and at least one of them is a QObject-derived one), then put all this classes inside a separated header file and include that file in your "main" class' header file. This way you not only skirted the problem, but also added some better organization to your codes.

God bless you! Have a nice day!

References

No comments:

Post a Comment