-
-
Save kmike/ff287998e02fa953b4a2 to your computer and use it in GitHub Desktop.
qt5 goes mad after reply.abort()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import sys | |
import sip | |
QT5 = True | |
if QT5: | |
from PyQt5.QtWidgets import QApplication | |
from PyQt5.QtWebKitWidgets import QWebView | |
from PyQt5.QtCore import QTimer, QUrl, PYQT_VERSION_STR, QT_VERSION_STR | |
from PyQt5.QtNetwork import QNetworkAccessManager | |
from PyQt5.QtWebKit import qWebKitVersion | |
else: | |
from PyQt4.QtGui import QApplication | |
from PyQt4.QtWebKit import QWebView | |
from PyQt4.QtCore import QTimer, QUrl, PYQT_VERSION_STR, QT_VERSION_STR | |
from PyQt4.QtNetwork import QNetworkAccessManager | |
from PyQt4.QtWebKit import qWebKitVersion | |
class CustomNAM(QNetworkAccessManager): | |
timers = set() | |
def createRequest(self, operation, request, outgoingData=None): | |
print("createRequest", request.url()) | |
reply = super(CustomNAM, self).createRequest(operation, request, outgoingData) | |
reply.metaDataChanged.emit() | |
timer = QTimer(reply) | |
timer.setSingleShot(True) | |
def on_timeout(): | |
print("aborting", reply.url()) | |
# reply.finished.disconnect() | |
reply.abort() | |
timer.timeout.connect(on_timeout) | |
timer.start(2000) | |
self.timers.add(timer) | |
return reply | |
def print_versions(): | |
versions = [ | |
"Qt %s" % QT_VERSION_STR, | |
"PyQt %s" % PYQT_VERSION_STR, | |
"WebKit %s" % qWebKitVersion(), | |
"sip %s" % sip.SIP_VERSION_STR, | |
] | |
print(", ".join(versions)) | |
if __name__ == '__main__': | |
print_versions() | |
app = QApplication(sys.argv) | |
nam = CustomNAM() | |
web_view = QWebView() | |
web_view.page().setNetworkAccessManager(nam) | |
web_view.show() | |
web_view.load(QUrl('http://0.0.0.0:8998/slow.gif?n=5')) | |
# web_view.setHtml(b''' | |
# <html><body> | |
# <img id='foo' width=50 heigth=50 | |
# src="http://www.deelay.me/5000/http://www.deelay.me/img/1000ms.gif""> | |
# </body></html> | |
# ''') | |
app.exec_() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment