2016-04-06 7 views
1

私はpyQt4を使用しています。私はpyQt5を変換したいと思います。 しかし、pyQt5はnew-style signal and slotしかサポートしていないので、old-style signal and slotをpyQt5に使用できませんでした。 したがって、ActiveXからイベントを受信できませんでした。pyQt5で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") 
+0

? – ekhumoro

答えて

2

私は最後に解決策を見つけました。 pyQt5は、ActiveXイベントからの信号をサポートします。

ActiveXに 'OnReceiveMsg'イベントがある場合、QAxWidgetインスタンスは 'OnReceiveMsg'シグナルをサポートします。 したがって、私はこのようなコードを修正します。ただ、(http://pyqt.sourceforge.net/Docs/PyQt5/signals_slots.html#connecting-slots-by-name)[名前でスロットを接続]ビットを推測するが、あなたのことができるようになり

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") 
関連する問題