Better workaround for hang-with-warnings bug

This commit is contained in:
Florian Bruhin 2014-06-25 20:18:00 +02:00
parent a03d209cb0
commit fcc0d8e911
2 changed files with 14 additions and 14 deletions

View File

@ -146,27 +146,18 @@ class NetworkManager(QNetworkAccessManager):
if accept_language is not None:
req.setRawHeader('Accept-Language'.encode('ascii'),
accept_language.encode('ascii'))
if (op == QNetworkAccessManager.PostOperation and
not req.header(QNetworkRequest.ContentTypeHeader)):
# If we don't do this workaround, we get a freeze on
with log.disable_qt_msghandler():
# If we don't disable our message handler, we get a freeze on
# http://ch.mouser.com/localsites/ when clicking on a currency.
# We basically do the same thing as Qt would do by itself in
# src/network/access/qhttpnetworkrequest.cpp ->
# QHttpNetworkRequestPrivate::header but somehow it doesn't
# freeze when we do it here.
#
# FIXME: Open questions:
#
# - Shouldn't QtWebPage set the content-type correctly by
# itself?
#
# - Why does Qt freeze if we don't do that? Why doesn't it
# happen with the minimal browser? It should really only
# print a warning and nothing else... Maybe message
# handler?!
req.setHeader(QNetworkRequest.ContentTypeHeader,
'application/x-www-form-urlencoded')
reply = super().createRequest(op, req, outgoing_data)
# - Why does Qt freeze if we don't disable our message
# handler?
reply = super().createRequest(op, req, outgoing_data)
self._requests.append(reply)
reply.destroyed.connect(lambda obj: self._requests.remove(obj))
return reply

View File

@ -24,6 +24,7 @@ import os
import sys
import cgi
import logging
from contextlib import contextmanager
from logging import getLogger
from collections import deque
@ -114,6 +115,14 @@ def init_log(args):
qInstallMessageHandler(qt_message_handler)
@contextmanager
def disable_qt_msghandler():
"""Contextmanager which temporarely disables the Qt message handler."""
old_handler = qInstallMessageHandler(None)
yield
qInstallMessageHandler(old_handler)
def fix_rfc2622():
"""Fix the rfc6266 logger.