On Fri, May 13, 2016 at 2:43 PM, d3fault <d3faultdot...@gmail.com> wrote:
> It's to work around the diamond inheritance problem, so yea admittedly > it's ugly. Know a cleaner way? I'm all ears. > Declare your signals directly into the classes that provide them and connect compatible methods, that'd be the cleaner way. But, yes, I admit, it doesn't work with an abstract class like you want. > 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. > I would assume this warning was put there for a reason by the Qt devs, wouldn't you? > If they're both reinterpret_casts then it compiles but segfaults. > Of course it segfaults, these aren't POD structures, they have pointers to the virtual tables, you can't just reinterpret_cast from one type to the other. That's why dynamic_cast was invented in the first place. If you properly cast to QObject * (that is with dynamic_cast) the result is like from the previous connect: "QObject::connect: signal not found in A" > Please download the attachment and test out your connect statements (both > compilation and execution) before responding with another attempt. > I had duly noted that the snippet I provided wan't tested, so there's no need to get overly excited. 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. > It does, but so does the moc generated data. It's how qobject_cast works without RTTI in the first place, it basically does what RTTI does, and even some more. As a side note, I remembered how you can cast to the interface without the need of RTTI: Declare the interface with Q_DECLARE_INTERFACE and list in the Q_INTERFACES macro the interfaces you implement. Then you can do qobject_cast<Interface *>(a); (where a is QObject *).
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest