如何配置QWebView
以降低网络超时值 - 以便在发生网络故障时,loadFinished(bool ok)
信号可以更快到达,显然,false
值并设置了适当的错误条件?
以不同方式处理不同超时的奖励积分
答案 0 :(得分:4)
标准错误和成功的页面加载将以与以前相同的方式触发loadFinished,但是自定义计时器将停止加载网页并使用ok = False触发loadFinished
class Browser(object):
def __init__(self):
self.web_view = QWebView()
self.web_view.loadFinished.connect(self._load_finished)
self._error = None
def perform(self, url, timeout_value=30):
request = QNetworkRequest()
request.setUrl(QUrl(url))
self.timeout_timer = QTimer()
self.timeout_timer.timeout.connect(self._request_timed_out)
self.timeout_timer.start(timeout_value * 1000)
self.web_view.load(request)
def _request_timed_out(self):
self._error = 'Custom request timeout value exceeded.'
self.timeout_timer.stop()
self.web_view.stop()
self.loadFinished.emit(False)
def _load_finished(self, ok):
pass
# ok is now False, and self._error contains a custom error message