我有以下代码:
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()));
}
我想向谷歌服务器发送查询并获得响应,但是当我发送请求时,上述插槽都没有调用,那我做错了什么?如果我把那个地址放在我的浏览器中,我会得到一些数据。