1

I've been using pyQt4. I'd like to convert pyQt5. but, I couldn't use old-style signal and slot in pyQt5 because pyQt5 supports only new-style signal and slot. Therefore, I couldn't receive events from ActiveX.

Please, give me solution.

this code is pyQt4 version.

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.

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") 
  • Just guessing a bit, but would you be able to [connect slots by name](http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html#connecting-slots-by-name)? – ekhumoro Apr 06 '16 at 17:07

1 Answers1

2

I found out the solution, finally. pyQt5 supports signals from ActiveX events.

If ActiveX has 'OnReceiveMsg' event, QAxWidget instance supports 'OnReceiveMsg' signal. 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")