For completeness I've attached a minimal compiling + working example of a "Signals & Slots Interface" that requires the Qt4-style connect syntax in order to use, which also means the interface implementers must use the "slots:" section in their class declaration/header (as per the subject of these emails).
On Sun, May 8, 2016 at 4:41 AM, Nye <kshegu...@gmail.com> wrote > > I suppose, but this very much smells like abusing the API, forgive me from > saying. > It's to work around the diamond inheritance problem, so yea admittedly it's ugly. Know a cleaner way? I'm all ears. > I had made some testing and moc complains (rightfully so) that signals > can't be virtual. > They can be pure virtual in the interface, just don't mark them virtual in the derived classes and you won't get that warning. > QObject::connect(a->asQObject(), static_cast<void > (QObject::*)()>(&Interface::someSignal), b->asQObject(), > reinterpret_cast<void (QObject::*)()>(&Interface::someSlot)); > Does not compile. If they're both reinterpret_casts then it compiles but segfaults. Please download the attachment and test out your connect statements (both compilation and execution) before responding with another attempt. 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. > RTTI has overhead, and while you're right that "forcing the interface to know about implementation details of derived classes" is usually a bad idea, in this case the goal is to make a "signals & slots interface", so it's guaranteed that all derived classes will ultimately inherit QObject. Lastly, I'll mention that I didn't come up with any of these techniques. I picked them up over the years from random blogs/forums/IRC/lists/etc. d3fault >
SignalsSlotsInterfaceExample.7z
Description: application/7z-compressed
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest