I am trying to connect to a signal in a base class. The pointer is the type of the base class but points to an object of the derived class. My classes are declared similar to the following:
{
Q_OBJECT
public:
Base();
signals:
void BaseSignal(char Arg);
};
class DerivA : public Base
{
Q_OBJECT
public:
DerivA();
void Alert() { emit BaseSignal('A') };
};
class DerivB : public Base
{
Q_OBJECT
public:
DerivB();
void Alert() { emit BaseSignal('B') };
};
class Base : public QObject
{
Q_OBJECT
public:
Base();
signals:
void BaseSignal(char Arg);
};
class DerivA : public Base
{
Q_OBJECT
public:
DerivA();
void Alert() { emit BaseSignal('A') };
};
class DerivB : public Base
{
Q_OBJECT
public:
DerivB();
void Alert() { emit BaseSignal('B') };
};
To copy to clipboard, switch view to plain text mode
Connect fails if I pass a DerivA or DerivB pointer to a function like the following:
bool SomeObject::mbrConnect(Base *B)
{
return QObject::connect(B,
SIGNAL(BaseSignal
(char)),
this,
SLOT(Handler
(char));
}
bool SomeObject::mbrConnect(Base *B)
{
return QObject::connect(B, SIGNAL(BaseSignal(char)), this, SLOT(Handler(char));
}
To copy to clipboard, switch view to plain text mode
It seems it is too smart for its own good, being able to identify the real type of the Base pointer in the Connect Fail output message. For example, passing mbrConnect a DerivA pointer would output the following:
Object::connect: No such signal DerivA::BaseSignal(char)
How do I solve this?
Bookmarks