0
votes

I am programming an application with a user interface. This interface has a couple of LideEdit objects and a checkable GroupBox, all contained at MainWindow class. When the user change the state of the checkable GroupBox, it emit a signal called system_toogled(int, int, std::string).

So MainWindow class has the following definition:

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_groupBox_toggled(bool arg1);

signals:
    void system_toogled(int, int, std::string);

private:
    Ui::MainWindow *ui;
};

The signal system_toogled(int, int, std::string) is emitted at the on_groupBox_toggled(bool arg1) that has the following definition:

void MainWindow::on_groupBox_toggled(bool arg1)
{
        emit system_toggled(ui->lineEdit->text().toInt(),
                            ui->lineEdit_2->text().toInt(),
                            ui->lineEdit_3->text().toStdString())
}

I also have a class called myProgramThread that is derivated from QThread class. It has the following definition:

class myProgramThread : public QThread
{
    Q_OBJECT

public:
    myProgramThread(MainWindow* mainWindow);

public slots:
    void on_system_toggled(int, int, std::string);

protected:
    void run();
};

The public slot called: on_system_toogled(int, int, std::string) manipulates these variables. I tried to connect the signal and the public slot with the function: connect() inside of the myProgramThread class constructor that has the following definition:

myProgramThread::myProgramThread(MainWindow* mainWindow)
{
    connect(mainWindow, SIGNAL(system_toggled(int, int, std::string)), this, SLOT(on_system_toggled(int, int, std::string)));
}

It is not working. I keep getting the following application output while debugging:

QMetaObject::connectSlotsByName: No matching signal for on_system_toogled(int,int,std::string)

So my question is: how can I connect a signal from MainWindow Class to another thread's slot?

1
Please show enough code to provide some context -- preferably a minimal reproducible example. As an aside, have you registered std::string?G.M.
Show your code pleaseVladimir Bershov
1. Replace Qt4-style connect to Qt5-style connect. 2. Rename your slot and get rid of on_, it's triggrring name-based connection, which can be a problem. 3. I'm afraid this won't work as long as (as far as I can see) your thread doesn't have an event loop.Bearded Beaver

1 Answers

0
votes

How do you know that it does not work? Did you check the return value of the connect() function? What you see is due to the somehow misleading naming of your slot which triggers the autoconnect feature of Qt.