问题:
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信号,这个信号意思是数据返回结束后才用的,如果后面还有数据要传回来,那么这个信号不适用