Solved Problems with QNetwork | QNetworkAccessManager
-
@SGaist updated the code above... that is the entire code!
-
Why are you using threads ?
QNAM is asynchronous so there's currently no need for threads especially in the first stage of development like that. -
@SGaist the reason for using threading is because i need to check constantly if the board im controlling is online or not. without threading QNAM only runs once
-
Use a QTimer to trigger sending your ping requests at regular intervals.
-
@SGaist what the..... QTimer fixed it... ok i need to read about QTimer!
-
@SGaist but yea still having the problem that the QNetworkReply does not give any error or output on boards that are offfline :S
else: print("Error occured: ", er) print(reply.errorString())
-
i dont understand why it doesn't give error not even (timeouterror)
-
anyone who can help?
-
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)