qt QNetworkReply/QNetworkAccessManager 接收SSE数据流的处理

问题:

QNetworkAccessManager /QNetworkReply通过get命令得到数据流:

这个数据流的特征是,当服务器有数据更新时,会实时传给我们。

Open a Server-Send Events (SSEs) stream, with a text/event-stream Content-Type

例如返回的filed是data的,需要怎么处理呢?

 

在qt'的网页QNetworkAccessManager /QNetworkReply两个class中我们都可以找到这杨一段话:

[signal] void QIODevice::readyRead()

/************************************************************************************************************************************************This signal is emitted once every time new data is available for reading from the device's current read channel. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.

readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true).

Note for developers implementing classes derived from QIODevice: you should always emit readyRead() when new data has arrived (do not emit it only because there's data still to be read in your buffers). Do not emit readyRead() in other conditions.************************************************************************************************************************************/

意思就是服务器get后会发送数据给我们,使用readyread()信号连接的话,当重新有数据更新时,程序会自动发送readyread()信号,当然了,槽函数你可以任意对数据进行处理,每次只会接受一个data块,下次数据更新后再提交信号,以此类推。。。

 

 

备注:QNetworkReply还有一个finished信号,这个信号意思是数据返回结束后才用的,如果后面还有数据要传回来,那么这个信号不适用

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值