Can someone explain to me why the overridden method is not called in the base class slot, instead I have the base version of the method:
class ThreadsDispatcher : public QObject { Q_OBJECT public: explicit ThreadsDispatcher(QObject *parent = 0); virtual ~ThreadsDispatcher(); virtual void OnThreadFinished(IThreadable *pWorker); public slots: void slotThreadFinished(IThreadable *pWorker); }; void ThreadsDispatcher::slotThreadFinished(IThreadable *pWorker) { OnThreadFinished(pWorker); } void ThreadsDispatcher::OnThreadFinished(IThreadable *pWorker) { qDebug << "Base method, class" << this->metaObject()->className(); }
Subclass:
class CommandsQueueDispatcher : public ThreadsDispatcher { Q_OBJECT public: explicit CommandsQueueDispatcher(CommandFactory* baseFactory, QObject *parent = 0); ~CommandsQueueDispatcher(); void OnThreadFinished(IThreadable *pWorker); }; void CommandsQueueDispatcher::OnThreadFinished(IThreadable *pWorker) { qDebug << "Subclass method, class" << this->metaObject()->className(); }
After calling OnThreadFinished in the slot, I get:
Base method, class ThreadsDispatcher
If I call the OnThreadFinished method from another method, I become normal:
Subclass method, class CommandsQueueDispatcher
I tried connecting in the base class and subclass, but there were no changes:
connect(pThreadWorker, SIGNAL(sigFinished(IThreadable*)), this, SLOT(slotThreadFinished(IThreadable*)));
But if I connect from another class, that is, neither a subclass, nor a base class:
connect(pThreadWorker, SIGNAL(sigFinished(IThreadable*)), pWorker, SLOT(slotThreadFinished(IThreadable*)));
where I need to replace this
with ptr
variable, I get a normal result.
Function in which I connect:
bool ThreadsDispatcher::AddThread(IThreadable* pThreadWorker) { connect(pThreadWorker, SIGNAL(sigFinished(IThreadable*)), this, SLOT(slotThreadFinished(IThreadable*))); }
I do not create ThreadsDispatcher directly. I create a CommandsQueueDispatcher object non-static.