多次使用 QNetworkAccessManager GET [英] using QNetworkAccessManager GET multiple times

查看:38
本文介绍了多次使用 QNetworkAccessManager GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序来以相等的时间间隔请求一个网页,以获取其中的任何更改(检查是否收到新数据).在这里我是如何做到的.

I am writing an application to request a web page at equal intervals in order to get any changes in it (to check whether new data is received). here how i did it.

 private:

 QNetworkReply *r;
 QNetworkAccessManager *m;
 QNetworkRequest request;
 QTimer *timer;

在构造函数中,

m = new QNetworkAccessManager(this);
timer = new QTimer(this);
connect(r , SIGNAL(readyRead()), this , SLOT(readit()));
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(1000);

读取功能,

void MainWindow::readit(){
QString st;
st=r->readAll();
m->deleteResource(request);
ui->textBrowser->append(st);
}

更新功能,

void MainWindow::update()
{
 request.setUrl(QUrl("http://localhost/test/default.php"));
 r = m->get(request);
}

我的问题是 m->get(request) 仅在第一次调用时获取请求,再次调用时它什么也不做.我做了几次实验,但最终没有成功的结果.我使用按钮单击将第二个请求更改为另一个网页,但它也没有做任何事情.

my problem is m->get(request) gets the request at its first call only, when it is called again it does nothing. I did several experiments but end up with no success results. i changed the second request to another web page using a button click but it did nothing too.

所以我需要专家的帮助,如何更新获取请求并多次获得新回复.

So I need help from an expert how to update the get request and get new reply multiple times.

而且我还想知道我是否在做正确的事情,或者是否有比定期检查网站更可靠的方法来从服务器获取有关数据更改的数据.

and also i want to know am i doing a correct thing or is there mo reliable methods to get data on data change from the server than checking for the website at regular intervals.

推荐答案

我看到以下问题:

  1. readyRead 为每个请求触发任意次数 - 包括零次 (!),但您将其视为它只触发了一次.使用 finished 信号,这就是你想要的:触发一次,不多不少.

  1. readyRead fires an arbitrary number of times per request - including zero times (!), but you treat it as if it fired exactly once. Use the finished signal, which is does what you want: fires once, no more, no less.

update 槽不会将任何槽连接到请求.

The update slot doesn't connect any slots to the request.

这篇关于多次使用 QNetworkAccessManager GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆