gpt4 book ai didi

c++ - QNetworkAccessManager 不工作

转载 作者:行者123 更新时间:2023-11-28 05:40:41 25 4
gpt4 key购买 nike

我有以下代码:

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_networkAccessManager(new QNetworkAccessManager(this))
{
ui->setupUi(this);

connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyForGeoCoordinates(QNetworkReply*)));
getCoordinates();
}

void MainWindow::getCoordinates()
{
std::string query = "http://maps.google.com/maps/api/geocode/json?address=warsaw&sensor=false&language=en";
QNetworkRequest request(QUrl(QString::fromStdString(query)));
m_reply = m_networkAccessManager->get(request);

connect(m_reply, SIGNAL(finished()), this, SLOT(rep()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(m_reply, SIGNAL(readyRead()), this, SLOT(rep()));
}

并且我想向谷歌服务器发送查询并获得响应,但是当我发送请求时,上述插槽都不会调用,所以我做错了什么?如果我将该地址放入浏览器,我会得到一些数据。

最佳答案

好吧,我认为你在联系上犯了错误。它们必须在您调用 get() 函数之前声明。

关于c++ - QNetworkAccessManager 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37160849/

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