Important: Please read the Qt Code of Conduct -

Slot connected to signal emitted from thread does not get called

  • I have defined a new slot in a class that inherits from QThread:

    class MyThread : public QThread
        MyThread(QString fileName);
        void run() override;
        void addNewItem(int row, int col, QString text);
        QString fileName;

    In the Dialog class I have defined slot that should get called when the above signal will be emitted. This slot updates widget on UI:

    void Dialog::onAddNewItem(int row, int col, QString text)
        ui->tableWidget->setItem(row, col, new QTableWidgetItem(text));

    In the constructor of the Dialog class I have created the working thread and connected signal to a slot:

    worker = new MyThread(filePath);
    connect(worker, &MyThread::addNewItem, this, &Dialog::onAddNewItem);

    In the run() function I'm emitting the addNewItem signal but the onAddNewItem slot never gets called. Why is that?

  • @michalt38 Hi, you might want to check the excellent checklist made by Giuseppe D'Angelo : . For instance, you could test the connect to return true or that the connect does not gets deleted following thread destruction...

  • Lifetime Qt Champion


    One thing: to start your thread, call the start method, run will be called automatically in the new thread. Here, you will have your run method executed and then you connect the signal. Hence the slot will never be called.

Log in to reply