On Sun, May 8, 2016 at 8:27 AM, d3fault <d3faultdot...@gmail.com> wrote: > > You're right, my example didn't suffer from the diamond inheritance > problem. But suppose you want to inherit from a QWidget derived class (or > any of the QObject derived classes in Qt xD) in addition to the > signals/slots interface: if the interface itself derives from QObject, > you'd have diamond inheritance. >
I suppose, but this very much smells like abusing the API, forgive me from saying. I had made some testing and moc complains (rightfully so) that signals can't be virtual. > >> QObject * a = new A; >> QObject * b = new B; >> QObject::connect(a, A::someSignal, b, B::someSlot); >> >> should be working just fine. >> > > Yes it works, but you're no longer using an interface when you mention A > or B [in the connect statement]. > This compiles okay (and should probably be working as well, haven't tested it though): QObject * a = new A; QObject * b = new B; QObject::connect(a, static_cast<void (QObject::*)()>(&A::someSignal), b, reinterpret_cast<void (QObject::*)()>(&Interface::someSlot)); Note however the ugly casts! (the first one is simply because of the implicit upcasting, so if a is A * as it'd normally be it wouldn't be necessary) Still, I hold to my statement that this really looks like abusing the API (no matter the syntax used) ... Interface doesn't inherit from QObject, so qobject_cast doesn't work. I > don't compile with RTTI, so dynamic_cast is out. > Perhaps you should consider enabling it then (provided you compiler/platform supports it). No RTTI, means you cant query for the interface implementation and in my opinion toQObject() is much worse, as it actually forces the interface to know about implementation details of derived classes ... but then, in the end it's your choice. That does not compile. (even with the missing ampersands added it still > doesn't :-P) > Yep, forgot them in the hurry :] Kind regards, Konstantin.
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest