vtable error for Qt derived class

When we define a new class, we usually add Q_OBJECT macro in the beginning of the class if it's derived from QObject. The qmake will generate moc_XXX for this new created Qt derived class. However, if we accidentally forget to include this .h file to HEADERS in .pro file, we will get vtable error for this new created class!

What a stupid error of mine! In Qt creator, we don't need to really include the .h in HEADERS to get it work, but if we defined a Qt derived class in .h file, we have to include it in the HEADERS!

Thus, if you saw this "vtable error", please check the following:
  1. Define the class in .h file
  2. Add Q_OBJECT macro in the beginning of the class
  3. Run qmake
  4. Include .h file in the HEADERS in .pro file

留言

熱門文章