QNetworkAccessManager - 没有这样的信号

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")));
}

出于某种原因,这不起作用,我收到以下消息:

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

当您使用 SIGNAL 和 SLOT 宏连接信号时,您只需传递信号传输的数据类型,在您的情况下应该是:

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

虽然建议使用 new syntax:

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