gpt4 book ai didi

python - QtWebkit:永远不会执行 loadFinished 和 loadProgress 插槽

转载 作者:行者123 更新时间:2023-11-28 23:05:43 25 4
gpt4 key购买 nike

这是我正在试用的 Webkit 的基本 PyQt 代码。

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from PyQt4.QtNetwork import *

class XPrinter(QObject):

def __init__(self):
QObject.__init__(self)

def print_page_info(self, ok):
print ok

def print_load_started(self):
print 'started loading'

def print_load_percent(self, percent):
print percent


app = QApplication(sys.argv)

web = QWebView()
xprinter = XPrinter()
QObject.connect(web, SIGNAL("loadFinished()"), xprinter.print_page_info)
QObject.connect(web, SIGNAL("loadStarted()"), xprinter.print_load_started)
QObject.connect(web, SIGNAL("loadProgress()"), xprinter.print_load_percent)
web.load(QUrl("http://www.gnu.org"))
web.setWindowState(Qt.WindowMaximized)
web.show()

sys.exit(app.exec_())

我面临的问题是插槽 loadFinished 和 loadProgress 从未执行过。请告诉我哪里做错了?

最佳答案

尝试使用新的 style signals

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
from PyQt4.QtNetwork import *

class XPrinter(QObject):

def __init__(self):
QObject.__init__(self)

def print_page_info(self, ok):
print ok

def print_load_started(self):
print 'started loading'

def print_load_percent(self, percent):
print percent


app = QApplication(sys.argv)

web = QWebView()
xprinter = XPrinter()
web.loadFinished.connect(xprinter.print_page_info)
web.loadStarted.connect(xprinter.print_load_started)
web.loadProgress.connect(xprinter.print_load_percent)

web.load(QUrl("http://www.gnu.org"))
web.setWindowState(Qt.WindowMaximized)
web.show()

sys.exit(app.exec_())

编辑:你也有错误的签名 QWebview

QObject.connect(web, SIGNAL("loadFinished(bool)"), xprinter.print_page_info)
QObject.connect(web, SIGNAL("loadStarted()"), xprinter.print_load_started)
QObject.connect(web, SIGNAL("loadProgress(int )"), xprinter.print_load_percent)

关于python - QtWebkit:永远不会执行 loadFinished 和 loadProgress 插槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5765077/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com