Qt: either signal won't send, or slot is not called

Viewed 110

I have two Qt classes implied in this problem: MainWindow and otaManager.
I want to send a signal from otaManager and let MainWindow call a slot when it does.
Here's MainWindow.h (https://github.com/Kobo-InkBox/inkbox/blob/1d48a6d85ee5b0a4db86c1d9f49510d0d923b297/mainwindow.h#L104):

private slots:
    void openUpdateDialogOTA(bool open);
    ...

private:
    ...
    otaManager *otaManagerWindow;

MainWindow.cpp (https://github.com/Kobo-InkBox/inkbox/blob/1d48a6d85ee5b0a4db86c1d9f49510d0d923b297/mainwindow.cpp#L979-L993):

...
void MainWindow::openUpdateDialogOTA(bool open) {
    if(open == true) {
        global::otaUpdate::isUpdateOta = true;
        openUpdateDialog();
    }
    else {
        ;
    }
}


void MainWindow::launchOtaUpdater() {
    otaManagerWindow = new otaManager(this);
    connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool)));
    otaManagerWindow->setAttribute(Qt::WA_DeleteOnClose);
}

otaManager.h (https://github.com/Kobo-InkBox/inkbox/blob/1d48a6d85ee5b0a4db86c1d9f49510d0d923b297/otamanager.h#L21-L22):

...
signals:
    void canOtaUpdate(bool yesno);
...

otaManager.cpp (https://github.com/Kobo-InkBox/inkbox/blob/1d48a6d85ee5b0a4db86c1d9f49510d0d923b297/otamanager.cpp#L15-L30):

        ...
        if(global::otaUpdate::downloadOta != true) {
            string_writeconfig("/opt/ibxd", "ota_update_check\n");
            while(true) {
                if(QFile::exists("/run/can_ota_update") == true) {
                    if(checkconfig("/run/can_ota_update") == true) {
                        emit canOtaUpdate(true);
                        qDebug() << "OTA update is available!";
                        break;
                    }
                    else {
                        emit canOtaUpdate(false);
                        qDebug() << "No OTA update available.";
                        break;
                    }
                }
            }
       ...

When compiled and running, the program passes all the conditions in otaManager and outputs the "OTA update is available!" message via a QDebug call.
Though, either the slot is not being called by MainWindow when receiving the signal or it is not being sent, because the openUpdateDialogOTA function in MainWindow, even when I put some QDebug calls to see if it was even launched, does not output nor do anything.

I'm quite puzzled by all this because I did it this way for other classes in my project and it worked just fine.

2 Answers

You forget about receiver object:

connect(otaManagerWindow, SIGNAL(canOtaUpdate(bool)), SLOT(openUpdateDialogOTA(bool)));

Try to use new style for connect method:

connect(a, &A::OnSignal, b, &B::OnSlot);
Related