Cannot pass arguments to ActiveX COM object using PyQt4

久未见 提交于 2019-12-02 10:20:02
101

Turns out I had the syntax quite wrong, worked it out by using the generateDocumentation() function as mentioned here, and some parameter help from here. The working code looks like:

import sys
from PyQt4 import QtGui
from PyQt4 import QAxContainer
from PyQt4.QtCore import QVariant

class APTSystem(QAxContainer.QAxWidget):

    def __init__(self, parent):

        super(APTSystem, self).__init__()

        # connect to control
        self.setControl('{B74DB4BA-8C1E-4570-906E-FF65698D632E}')

        # required by device
        self.dynamicCall('StartCtrl()')

        # args must be list of QVariants
        typ = QVariant(6)
        num = QVariant(0)
        args = [typ, num]

        self.dynamicCall('GetNumHWUnits(int, int&)', args)

        # only list items are updated, not the original ints!
        if args[1].toInt()[1]:
            print 'Num of HW units =', args[1].toInt()[0]

        self.dynamicCall('StopCtrl()')

app = QtGui.QApplication(sys.argv)        
a = APTSystem(app)

The second item in the args list contains the correct value, but num is never updated by the call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!