Results 1 to 2 of 2

Thread: Slot/Signal mechanism and inheritance

  1. #1
    Join Date
    May 2020
    Qt products
    Qt4 Qt5 Qt/Embedded

    Default Slot/Signal mechanism and inheritance


    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
    // ...
    // ...
    public slots:
    void OnInterruptRequested(int id);
    void thread_interrupted(int id);

    } 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?
    "It isn't that life ashore is distasteful to me. But life at sea is better."

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 723 Times in 713 Posts
    Qt products
    Windows Android

    Default Re: Slot/Signal mechanism and inheritance

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    cpt-nil (3rd June 2020)

Similar Threads

  1. Efficiency of the signal and slot mechanism
    By Momergil in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2014, 19:28
  2. signal -slot mechanism
    By qt_user in forum Qt Programming
    Replies: 2
    Last Post: 30th July 2010, 18:34
  3. When should I use signal/slot mechanism
    By Bryku in forum Newbie
    Replies: 3
    Last Post: 10th February 2010, 22:24
  4. slow signal-slot-mechanism
    By blm in forum Qt Programming
    Replies: 11
    Last Post: 28th October 2008, 17:10
  5. The threaded signal/slot mechanism
    By xbtl in forum Newbie
    Replies: 1
    Last Post: 30th March 2008, 00:07


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.