【发布时间】:2017-03-09 16:24:13
【问题描述】:
我一直在使用 pyQt4。我想转换 pyQt5. 但是,我不能在 pyQt5 中使用 old-style signal and slot,因为 pyQt5 仅支持 new-style signal and slot。 因此,我无法从 ActiveX 接收事件。
请给我解决方案。
此代码为pyQt4版本。
from PyQt4.QtCore import SIGNAL, QObject
from PyQt4.QAxContainer import QAxWidget
class ActiveXExtend(QObject):
def __init__(self, view):
super().__init__()
self.view = view
self.ocx = QAxWidget("KHOPENAPI.KHOpenAPICtrl.1")
# receive ActiveX event.
self.ocx.connect(self.ocx, SIGNAL("OnReceiveMsg(QString, QString, QString, QString)"), self._OnReceiveMsg)
# event handler
def _OnReceiveMsg(self, scrNo, rQName, trCode, msg):
print("receive event")
我尝试转换 pyQt5。
from PyQt5.QtCore import QObject
from PyQt5.QAxContainer import QAxWidget
class ActiveXExtend(QObject):
def __init__(self, view):
super().__init__()
self.view = view
self.ocx = QAxWidget("KHOPENAPI.KHOpenAPICtrl.1")
# receive ActiveX event.
# old-style is not supported.
# self.ocx.connect(self.ocx, SIGNAL("OnReceiveMsg(QString, QString, QString, QString)"), self._OnReceiveMsg)
# event handler
def _OnReceiveMsg(self, scrNo, rQName, trCode, msg):
print("receive event")
【问题讨论】:
-
只是猜测一下,但你能connect slots by name吗?