Why is Qt looking for my slot in the base class instead of derived one?

陌路散爱 提交于 2020-01-03 06:45:12

问题


I have my class X which inherits from Qt's class Base. I declared and defined void mySlot() slot in my class X and I'm connecting some signal to this slot in X's constructor. However, when running my program I get an error message saying there's no such slot as void mySlot() in the class Base.

Why is the code generated by Meta Object Compiler (moc) looking for my slot in the base class and not in my (derived) class?


回答1:


Did you add the Q_OBJECT macro on the derived class?




回答2:


From #qt irc channel

  1. Make sure the Q_OBJECT macro is present in the definition of all QObject-derived classes.
  2. Make sure you declare your QObject-derived classes in your header files ONLY.
  3. Make sure all of your header files are listed in your .pro file in the HEADERS= list.
  4. Run qmake every time you add Q_OBJECT to one of your classes or modify your .pro file.


来源:https://stackoverflow.com/questions/1389680/why-is-qt-looking-for-my-slot-in-the-base-class-instead-of-derived-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!