[Qt-interest] Sending derived objects through queued connections
Mihail Naydenov
mlists at ymail.com
Thu Jun 3 09:32:00 CEST 2010
Singnal - slot calls are not that diff from normal func calls.
Most of the things you do with func calls should also work with signal/slots.
The catches are:
- return must be void
- You have to register the type you pass using qRegisterMetaType (if a custom one).
- The params are pasted aways by copy. (They need to be stored because the queued connection call is dеffered )
So these are the basics, you should try it yourself if your scenario works.
MihailNaydenov
----- Original Message ----
> From: Akos Polster <akos at pipacs.com>
> To: qt-interest at trolltech.com
> Sent: Thu, June 3, 2010 12:22:03 AM
> Subject: [Qt-interest] Sending derived objects through queued connections
>
> Hi,
is it possible to send derived objects via signals (over
> queued
connections), and be able to restore them on the receiver side.
> How
should my base and derived classes look like? Or any alternatives
> you
can recommend.
Naive example:
class Base {};
class
> Derived: public Base {};
class Emitter {
signals:
void
> bang(const Base &b);
};
class Receiver {
protected
> slots:
void onBang(const Base &b) {
if
> (magic_convert(b from Base to Derived)) {
// Bingo! Got
> a Derived object as signal parameter
}
> }
};
main() {
Emitter e;
Base b;
Derived
> d;
Receiver r;
connect(&e, SIGNAL(bang(const Base
> &)), &r, SLOT(onBang(const Base
&)), QueuedConnection);
> emit e.bang(d);
// run event loop
}
Thanks
~
> Akos.
_______________________________________________
Qt-interest mailing
> list
> href="mailto:Qt-interest at trolltech.com">Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list