I am having trouble calling a slot directly from subclass of QListWidget. It fails to link claiming an undefined reference to MyClass::MySlot. If instead of calling it, I just connect to slot and emit the appropriate signal everything works fine. It seems to me that it's probably a compiler/qmake/makefile issue but I'm not sure. Below is a rough approximation of the issue I'm having. I have omitted all the #include for the sake of brevity.

I have a subclass of QObject that looks roughly like

Qt Code:
  1. class MyClass : public QObject {
  2.  
  3. Q_OBJECT
  4.  
  5. public:
  6. MyClass(QObject* parent = NULL) : QObject(parent) { }
  7. void MyFunc() {
  8. // do some work
  9. }
  10.  
  11. public slots:
  12. void MySlot() {
  13. // do some work
  14. }
  15. }
To copy to clipboard, switch view to plain text mode 

And...

Qt Code:
  1. class MyListWidget : public QListWidget {
  2.  
  3. Q_OBJECT
  4.  
  5. private:
  6. MyClass* foo;
  7.  
  8. public:
  9. MyListWidget(QWidget* parent = NULL) : QListWidget(parent) { }
  10.  
  11. public slots:
  12. void bar() {
  13. // won't compile, linker fails - undefined reference to 'MyClass::MySlot'
  14. foo->MySlot();
  15. }
  16.  
  17. void baz() {
  18. // this compiles and works fine
  19. QObject::connect(this, SIGNAL(callSlot), foo, SLOT(MySlot()));
  20. emit callSlot();
  21. QObject::disconnect(this, SIGNAL(callSlot), foo, SLOT(MySlot()));
  22.  
  23. // also works
  24. foo->MyFunc();
  25. }
  26.  
  27. signals:
  28. void callSlot();
  29. }
To copy to clipboard, switch view to plain text mode