Search code examples
c++qtqtnetwork

QNetworkAccessManager - No such signal


void MainWindow::handleGetReply(QNetworkReply  *reply)
{
    qDebug() << reply;
}

void MainWindow::on_getDetailsButton_clicked()
{
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    connect(
                manager,
                SIGNAL(finished(QNetwokReply *reply)),
                this,
                SLOT(handleGetReply(QNetworkReply*)));
    manager->get(QNetworkRequest(QUrl("http://google.com")));
}

For some reason this doesn't work, and I have the following message:

QObject::connect: No such signal QNetworkAccessManager::finished(QNetwokReply *reply) in ..\MyApplication\mainwindow.cpp:63
QObject::connect:  (receiver name: 'MainWindow')

Solution

  • When you connect the signal using the SIGNAL and SLOT macros, you only need to pass the type of data that the signal transports, in your case it should be:

    connect(manager, 
            SIGNAL(finished(QNetworkReply *)), 
            this, 
            SLOT(handleGetReply(QNetworkReply*)));
    

    Although it is advisable to use the new syntax:

    connect(manager, 
            &QNetworkAccessManager::finished, 
            this, 
            &MainWindow::handleGetReply);