Solved Problems with QNetwork | QNetworkAccessManager
-
IIRC, the default timeout is 30 seconds, did you wait that long ?
-
@SGaist i set 3000 on the Qtimer
self.ping = QTimer(self) self.ping.start(3000) self.ping.timeout.connect(self.doRequest)
-
@Kris-Revi I think @SGaist means timeouts for network requests
-
@jsulm oh, i googled and saw many forum threads saying that you couldn't set timeout in Qt, granted the posts were a few years old! how do i set timeout?
-
@Kris-Revi First thing would be to wait at least 30sec (default timeout) to see whether you get the timeout error.
-
@jsulm i waited a looong time and i got "Error : 99 Timeout" but is there anyway to set timeout?
-
-
@SGaist where do i put this?
-
@jsulm where do i put this?
QNetworkConfiguration.setConnectTimeout(1)
-
@Kris-Revi Get the active configuration using https://doc.qt.io/qt-5/qnetworkaccessmanager.html#activeConfiguration and call setConnectTimeout on it...
-
@jsulm i miss examples in the docs :/ as im a beginner at Qt and python in general!
-
Just a note:
The "1" means 1 millisecond. To wait one second, pass "1000".Put these lines below the part, where you establish your connection. (Get
QNetworkConfiguration
first, then set your timeout value) -
@Pl45m4 like this?
self.nam = QtNetwork.QNetworkAccessManager() self.nam.finished.connect(self.handleResponse) def doRequest(self): print("Run") print("#----------------------------------#") for key, value in self.board.items(): url = "http://" + value["ip"] print("doRequests : http://" + value["ip"]) req = QtNetwork.QNetworkRequest(QUrl(url)) self.nam.get(req) self.nam.activeConfiguration() QtNetwork.QNetworkConfiguration.setConnectTimeout(1000)
-
No, do it once in the constructor. The setting will apply to all future requests.