gpt4 book ai didi

c++ - QNetworkAccessManager 不发出信号

转载 作者:行者123 更新时间:2023-11-30 05:27:30 27 4
gpt4 key购买 nike

所以我有这段代码:

QUrl url("http://...");
QNetworkRequest request(url);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()), SLOT(onRequestCompleted()));
connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),SLOT(onError(QNetworkReply::NetworkError)));

我不能得到其他功能的信号

void IpResolver::onRequestCompleted()
{
QString webContent;

QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());

if (reply)
{
if (reply->error() == QNetworkReply::NoError)
{
QString webContent = reply->readAll();
}
}
}

我想不出解决办法,请帮忙。

最佳答案

我不知道你到底想要什么,但是:

  1. 为什么使用回复指针而不是某种onRequestCompleted(QNetworkReply *reply)
  2. 如果你这样做:

    QUrl url("http://...");
    QNetworkRequest request(url);
    connect(m_networkManager, &QNetworkAccessManager::finished, this, &IpResolver::onRequestCompleted);
    m_networkManager->get(request);
  3. 例如,您的插槽将是:

    void IpResolver::onRequestCompleted(QNetworkReply *reply)
    {
    QString webContent;
    if (reply->error() == QNetworkReply::NoError)
    webContent = reply->readAll();
    }

关于c++ - QNetworkAccessManager 不发出信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37285129/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com