Windows 32 上的 PySide 和 VTK

Posted

技术标签:

【中文标题】Windows 32 上的 PySide 和 VTK【英文标题】:PySide and VTK on Windows 32 【发布时间】:2013-04-04 14:10:37 【问题描述】:

我有一个 PySide/VTK 应用程序,使用 QVTKRenderWindowInteractor 连接。 PySide 1.0.9 在带有 QT4.8/VTK 5.8 的基于 Unix 的系统上运行良好。 (所有 Python 2.7.3)

然后我移植到 Microsoft Windows 系统 (XP 32) 上,使用 PySide win32 分发版 (1.1.x) Qt4 和 VTK 5.10,我在 QVTKRenderWindowInteractor 中出现类型错误,同时检索 self.winId()可转换为 int:

TypeError: int() argument must be a string or a number, not 'PyCObject'

PySide API 实际上说 PySide.QtGui.QWidget.winId() 返回一个 long...

我正在 MS-Windows 和 Unix 上开始更多测试,但也许你们中的一些人可以给我一些建议? 我必须在哪里寻找什么?

这可能与 32 位 系统上的这个 long 的错误转换有关,由 PySide 接口生成器生成到 Qt?

见第 152 行 http://sourceforge.net/p/pycgns/code/ci/17b696c3b0ad2b387b7e0ddc5d9b195cbc6abf70/tree/NAVigater/CGNS/NAV/Q7VTKRenderWindowInteractor.py

【问题讨论】:

注册为 PySide 错误:bugreports.qt-project.org/browse/PYSIDE-46 并使用此错误报告中描述的提示进行修复。 【参考方案1】:

将此行替换为:

WId = self.winId()

if type(WId).__name__ == 'PyCObject':
    from ctypes import pythonapi, c_void_p, py_object

    pythonapi.PyCObject_AsVoidPtr.restype  = c_void_p
    pythonapi.PyCObject_AsVoidPtr.argtypes = [py_object]

    WId = pythonapi.PyCObject_AsVoidPtr(WId)

self._RenderWindow.SetWindowInfo(str(int(WId)))

【讨论】:

以上是关于Windows 32 上的 PySide 和 VTK的主要内容,如果未能解决你的问题,请参考以下文章