PDA

View Full Version : Slot/Signal mechanism and inheritance



cpt-nil
3rd June 2020, 21:10
Hi,

I have a general question regarding the slot/signal mechanism and inheritance:
I have an application with a Qt-based GUI that shall have at least 4 components running in dedicated threads. I do not subclass QThread but use the moveToThread() approach
For interrupt handling issues I added a base class for the thread_worker objects where the interrupt handling is implemented:

class AbstractThreadWorker : public QObject
{
Q_OBJECT
// ...
// ...
public slots:
void OnInterruptRequested(int id);
signals:
void thread_interrupted(int id);

}

...is it possible to use the connect() method (in the main thread) on the base class (one connect for all therad workers) or do I have to connect these signals/slots for each sub classed (i.e. ThreadWortker that inherits from AbstractThreadWorker) ThreadWorker?
Regards

d_stranz
3rd June 2020, 21:48
If you are creating unique AbstractThreadWorker instance for each thread, then you need to connect() each one of them. You do not connect a class, you connect an instance of a class.