QNetworkAccessManager - No such signal

孤街浪徒 提交于 2019-12-11 01:48:21

问题


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')

回答1:


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


来源:https://stackoverflow.com/questions/48238544/qnetworkaccessmanager-no-such-signal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!