gpt4 book ai didi

python - 如何在pyQt5中接收ActiveX事件?

转载 作者:行者123 更新时间:2023-12-01 04:01:24 26 4
gpt4 key购买 nike

我一直在使用pyQt4。我想转换 pyQt5.但是,我无法使用old-style signal and slot在 pyQt5 中,因为 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")

最佳答案

终于找到解决办法了。 pyQt5 支持来自 ActiveX 事件的信号。

如果 ActiveX 有“OnReceiveMsg”事件,QAxWidget 实例支持“OnReceiveMsg”信号。因此,我修复了这样的代码。

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.
self.ocx.OnReceiveMsg[str,str,str,str].connect(self._OnReceiveMsg)

# event handler
def _OnReceiveMsg(self, scrNo, rQName, trCode, msg):
print("receive event")

关于python - 如何在pyQt5中接收ActiveX事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36442631/

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