How to obtain QNetworkAccessManager's connection states?
-
12-11-2019 - |
Вопрос
I need to see different connection states of QNetworkAccessManager. How to do it or is it even possible with QT?
Example in QHttp, there is enum state: QHttp enum state
QTCPSocket, there is SocketState: QAbstractSocket state
Most important for me is to know when manager is connected to host and just before manager starts to upload data.
Решение
Like Phil has mentioned QNetworkAccessManager has abstracted most of the methods. To get the connection state use QNetworkSession before you work with the QNetworkAccessManager.
To get the state of the current session, use this state function ( http://doc.qt.nokia.com/qtmobility/qnetworksession.html#State-enum)
Reading the complete documentation here is going to help you much. http://doc.qt.nokia.com/qtmobility/qnetworksession.html
Другие советы
In the past I posted and connect to the finished signal. This contains the reply that lets you know if the transfer had errors. There is also the networkAccessibleChanged signal if you want to detect when you go offline.
QNetworkAccessManager
is higher level than QHttp
and QTCPSocket
so they have abstracted away the sockets connection state.