If I declare a function virtual in the base non-QObject class and then overlaod it as a slot in the derived class that has Q_OBJECT macro and that has QObject as one of the base classes is it supposed to work ok?
Is it guaranteed that virtual calls will work? What should happen if you connenct to the slot of the derived class?
class Base
{
public:
virtual void f();
};
class Derived: public QObject, public Base
{
Q_OBJECT
public slots:
virtual void f();
};
Yes:
http://qt-project.org/doc/qt-4.8/signalsandslots.html#slots
In your example
Derived::fis a normal virtual function. If it’s called directly, it works as expected, just as the documentation says. When invoked by signal, it’s called byqt_static_metacall, which is generated inmoc_Derived.cppas following:So, it ends with normal function call
_t->f().Note that there is no way to invoke
Base::fby a signal. This function can be executed only if present object is actuallyBaseinstance and notDerivedinstance. And sinceBaseis not QObject-based, you can’t pass its instance toconnectfunction.