[PyQt] Connect PyQt to ActiveX events

Sam Myers morefigs at gmail.com
Tue Feb 3 03:54:57 GMT 2015


I'm using an ActiveX object to control some hardware stages. So far a
simple example class like the following works fine:

from PyQt4 import QAxContainer
from PyQt4.QtCore import QVariant

class MG17Motor(QAxContainer.QAxWidget):
    def __init__(self):
        super(MG17Motor, self).__init__()
        self.setControl('{3CE35BF3-1E13-4D2C-8C0B-DEF6314420B3}')

    def set_serial_num(self, hw_serial_num):
        ser = QVariant(hw_serial_num)
        args = [ser]
        self.dynamicCall('SetHWSerialNum(int)', args)

How would I expand this class to also listen for ActiveX events, e.g. call
a Python function when an ActiveX object event occurs. For instance to
connect to the MoveComplete event, from the generated stage hardware docs
(in C++):

QObject::connect(object, SIGNAL(MoveComplete(int)), receiver,
SLOT(someSlot(int)));

But I can't work out the equivalent Python code. None of these work:

self.connect(self, QtCore.SIGNAL('MoveComplete(int)'), self,
QtCore.SLOT(self.myfunc))
self.connect(self, QtCore.SIGNAL('MoveComplete(int)'), self.myfunc)
self.connect(self.MoveComplete(), QtCore.SIGNAL('MoveComplete(int)'), self,
QtCore.SLOT(self.myfunc))

There's also a reference to "request the COM interface directly using
QAxBase.queryInterface
<http://pyqt.sourceforge.net/Docs/PyQt4/qaxbase.html#queryInterface>()" in
the PyQt docs, but queryInterface doesn't seem to be a valid method of that
class.

Could someone enlighten me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150203/c1602cca/attachment-0001.html>


More information about the PyQt mailing list