I have a signal that is emitted w/a parameter taken from a subclass, but in one slot implementation, I don't need a special handler for the subclass; just the parent class. I thought that connect()
would upcast that parameter, but unfortunately, I get:
QObject::connect: Incompatible sender/receiver arguments
emitter::mysignal(messageSubclass *) --> slotter::generalHandler(messageSuperclass *)
In emitter
I have:
emit mysignal((messageSubclass *)msg_ptr );
There are various places in the code were I need to handle this messageSubclass
specifically. But, in one place, a whole family of signals can be handled by just one slot method, so I have:
connect(emitter_ptr, SIGNAL(mysignal(messageSubclass *)), this, SLOT(generalHandler(messageSuperclass *)));
I really don't want to have to have generalHandler()
be replaced by a couple of dozen specific handlers, that all do the same thing. Putting it another way, I'm trying to avoid something tedious like:
connect(emitter_ptr, SIGNAL(mysignal(messageSubclass *)), this, SLOT(specificHandler(messageSubclass *)));
connect(emitter_ptr, SIGNAL(mysignalA(messageSubclassA *)), this, SLOT(specificHandlerA(messageSubclassA *)));
connect(emitter_ptr, SIGNAL(mysignalB(messageSubclassB *)), this, SLOT(specificHandlerB(messageSubclassB *)));
connect(emitter_ptr, SIGNAL(mysignalC(messageSubclassC *)), this, SLOT(specificHandlerC(messageSubclassC *)));
...
void handlerClass::specificHandler(messageSubclass *msg_ptr) {
generalHandler((messageSuperclass *)msg_ptr);
}
void handlerClass::specificHandlerA(messageSubclassA *msg_ptr) {
generalHandler((messageSuperclass *)msg_ptr);
}
void handlerClass::specificHandlerB(messageSubclassB *msg_ptr) {
generalHandler((messageSuperclass *)msg_ptr);
}
void handlerClass::specificHandlerC(messageSubclassC *msg_ptr) {
generalHandler((messageSuperclass *)msg_ptr);
}
And again, I need to have
signals:
mysignal(messageSubclass *);
for other slots which need messageSubclass
.
I'm using Qt 4.8