Problem with Signal/Slot connections in derived classes
I have a problem with Signal/Slot connections when a slot exists in a derived class, but not the baseclass. Imagine the following code, where class A is derived from QObject, and class B is derived from class A.
Class A:
Code:
#include <QObject>
{
Q_OBJECT
public:
virtual ~A() {};
};
{
}
Class B:
Code:
#include "A.h"
class B : public A
{
public:
virtual ~B() {};
public slots:
void mySlot();
};
{
}
void B::mySlot()
{
qDebug("B::mySlot called");
}
Now I want to create an instance of class B, and connect the slot defined in class B (but not in class A!) to a signal.
Code:
B b;
QObject::connect(&app,
SIGNAL(aboutToQuit
()),
&b,
SLOT(mySlot
()));
Instead of the slot being called, I get the following warning in the debug output:
Code:
WARNING: Object::connect: No such slot A::mySlot()
WARNING: Object::connect: (sender name: 'tst_Qt')
Why does it try to connect to A::mySlot()? b is clearly an instance of B, not of A.
Qt is version 4.3.1. I'd be very happy about any hint to solve this problem..
Re: Problem with Signal/Slot connections in derived classes
Add the Q_OBJECT macro to B also.
Re: Problem with Signal/Slot connections in derived classes
Ouch. That was really a stupid mistake. Thanks for your help!