<tfoot id='WuKRn'></tfoot>

  • <small id='WuKRn'></small><noframes id='WuKRn'>

        <bdo id='WuKRn'></bdo><ul id='WuKRn'></ul>
      1. <i id='WuKRn'><tr id='WuKRn'><dt id='WuKRn'><q id='WuKRn'><span id='WuKRn'><b id='WuKRn'><form id='WuKRn'><ins id='WuKRn'></ins><ul id='WuKRn'></ul><sub id='WuKRn'></sub></form><legend id='WuKRn'></legend><bdo id='WuKRn'><pre id='WuKRn'><center id='WuKRn'></center></pre></bdo></b><th id='WuKRn'></th></span></q></dt></tr></i><div id='WuKRn'><tfoot id='WuKRn'></tfoot><dl id='WuKRn'><fieldset id='WuKRn'></fieldset></dl></div>
        <legend id='WuKRn'><style id='WuKRn'><dir id='WuKRn'><q id='WuKRn'></q></dir></style></legend>

        无法使用 PyQt4 将参数传递给 ActiveX COM 对象

        时间:2023-09-11
        • <tfoot id='GKcrD'></tfoot>
            1. <small id='GKcrD'></small><noframes id='GKcrD'>

                <tbody id='GKcrD'></tbody>

                <bdo id='GKcrD'></bdo><ul id='GKcrD'></ul>

                <i id='GKcrD'><tr id='GKcrD'><dt id='GKcrD'><q id='GKcrD'><span id='GKcrD'><b id='GKcrD'><form id='GKcrD'><ins id='GKcrD'></ins><ul id='GKcrD'></ul><sub id='GKcrD'></sub></form><legend id='GKcrD'></legend><bdo id='GKcrD'><pre id='GKcrD'><center id='GKcrD'></center></pre></bdo></b><th id='GKcrD'></th></span></q></dt></tr></i><div id='GKcrD'><tfoot id='GKcrD'></tfoot><dl id='GKcrD'><fieldset id='GKcrD'></fieldset></dl></div>

                  <legend id='GKcrD'><style id='GKcrD'><dir id='GKcrD'><q id='GKcrD'></q></dir></style></legend>
                1. 本文介绍了无法使用 PyQt4 将参数传递给 ActiveX COM 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试编写一些 Python 代码来与 Thorlabs APT ActiveX 控件通信.我的代码基于 在此页面,但尝试使用 PyQt4 ActiveX 容器而不是 wxPython ActiveX 容器.它适用于非常简单的 ActiveX 方法,但是在尝试调用带参数的方法时出现错误.

                  I'm trying to write some Python code to talk to the Thorlabs APT ActiveX control. I'm basing my code on the code found on this page, but trying to use PyQt4 ActiveX container instead of the wxPython ActiveX container. It works for a very simple ActiveX methods, however, I get an error when trying to call a method that takes arguments.

                  此代码有效并显示了 Thorlabs APT 的关于框:

                  This code works and shows the about box for Thorlabs APT:

                  import sys
                  from ctypes import *
                  
                  from PyQt4 import QtGui
                  from PyQt4 import QAxContainer
                  
                  class APTSystem(QAxContainer.QAxWidget):
                  
                      def __init__(self, parent):
                          self.parent = parent
                          super(APTSystem, self).__init__()
                  
                          self.setControl('{B74DB4BA-8C1E-4570-906E-FF65698D632E}')
                  
                          # calling this method works    
                          self.AboutBox()
                  
                  app = QtGui.QApplication(sys.argv)        
                  a = APTSystem(app)
                  

                  当我用带参数的方法替换 self.AboutBox() 时,例如:

                  When I replace self.AboutBox() with a method with arguments e.g.:

                  num_units = c_int()
                  self.GetNumHWUnitsEx(21, byref(num_units))
                  

                  我收到一个错误:TypeError: unable to convert argument 1 of APTSystem.GetNumHWUnitsEx from 'CArgObject' to 'int&'

                  我认为参数类型需要是 ctypes 类型.是否有一些 ctypes 魔法可以解决这个问题?

                  I presume the argument type needs to be a ctypes type. Is there some ctypes magic that can solve this?

                  推荐答案

                  原来我的语法完全错误,通过使用 generateDocumentation() 函数 这里提到,还有一些参数帮助从这里.工作代码如下所示:

                  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)
                  

                  args 列表中的第二项包含正确的值,但 num 永远不会被调用更新.

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

                  这篇关于无法使用 PyQt4 将参数传递给 ActiveX COM 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何将 POINT 结构传递给 Python 中的 ElementFromPoin 下一篇:无法在 Python 上使用 win32com 完全关闭 Excel

                  相关文章

                  最新文章

                  <tfoot id='ZQVcZ'></tfoot>

                  <small id='ZQVcZ'></small><noframes id='ZQVcZ'>

                        <bdo id='ZQVcZ'></bdo><ul id='ZQVcZ'></ul>
                      <i id='ZQVcZ'><tr id='ZQVcZ'><dt id='ZQVcZ'><q id='ZQVcZ'><span id='ZQVcZ'><b id='ZQVcZ'><form id='ZQVcZ'><ins id='ZQVcZ'></ins><ul id='ZQVcZ'></ul><sub id='ZQVcZ'></sub></form><legend id='ZQVcZ'></legend><bdo id='ZQVcZ'><pre id='ZQVcZ'><center id='ZQVcZ'></center></pre></bdo></b><th id='ZQVcZ'></th></span></q></dt></tr></i><div id='ZQVcZ'><tfoot id='ZQVcZ'></tfoot><dl id='ZQVcZ'><fieldset id='ZQVcZ'></fieldset></dl></div>

                      <legend id='ZQVcZ'><style id='ZQVcZ'><dir id='ZQVcZ'><q id='ZQVcZ'></q></dir></style></legend>