[英]How to receive ActiveX events in pyQt5?
I've been using pyQt4. 我一直在使用pyQt4。 I'd like to convert pyQt5.
我想转换pyQt5。 but, I couldn't use old-style signal and slot in pyQt5 because pyQt5 supports only new-style signal and slot .
但是,我无法在pyQt5中使用旧式信号和插槽 ,因为pyQt5仅支持新式信号和插槽 。 Therefore, I couldn't receive events from ActiveX.
因此,我无法从ActiveX接收事件。
Please, give me solution. 请给我解决方法。
this code is pyQt4 version. 这段代码是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")
I try to convert pyQt5. 我尝试转换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")
I found out the solution, finally. 我终于找到了解决方案。 pyQt5 supports signals from ActiveX events.
pyQt5支持来自ActiveX事件的信号。
If ActiveX has 'OnReceiveMsg' event, QAxWidget instance supports 'OnReceiveMsg' signal. 如果ActiveX具有“ OnReceiveMsg”事件,则QAxWidget实例支持“ OnReceiveMsg”信号。 Therefore, I fix code like this.
因此,我修复了这样的代码。
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.