将 pyqt 对象传递给 swig 导出的 c++代码
有人知道是否存在将 pyQt 对象传递给 C++ 代码的方法?
我会更好地解释;假设我有这个 c++ 代码
void QtGuiPDLVisitor::set_layout(QLayout* _layout){
layout = _layout;
}
,其中 QtGuiPDLVisitor 是使用 SWIG 在 python 中导出的 c++ 类,所以在 python 中我想做这样的事情,这
layout = QtGui.QGridLayout()
visitor = QtGuiPDLVisitor()
visitor.set_layout(layout)
可能吗? python解释器说不:(...有没有任何解决方法,比如传递指针的方法或任何其他黑客?
编辑:
Traceback (most recent call last):
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pipeworkarea.py", line 53, in create_new_computation
subWindowWidget.setComputation(idx.data())
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pypeWidgets.py", line 44, in setComputation
self.widBuilder.buildUi(self)
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pypeWidgets.py", line 63, in buildUi
pdlVisitor.set_layout(criteria_area_layout)
File "/home/picci/workspace/gestface/pipeit/wrap/python/dist/Debug/pipeit.py", line 736, in set_layout
def set_layout(self, *args) -> "void" : return _pipeit.QtGuiPDLVisitor_set_layout(self, *args)
TypeError: in method 'QtGuiPDLVisitor_set_layout', argument 2 of type 'QLayout *'
这是来自python的错误。我已经知道这个错误是由于Qt4是包装器的事实在python中使用SIP,虽然我使用SWIG来包装,但我认为必须有一种方法可以直接访问Qlayout对象的指针并将其从python传递给C++代码。
anyone knows if there exists a method for passing pyQt objects to c++ code?
I'll explain better; say i have this c++ code
void QtGuiPDLVisitor::set_layout(QLayout* _layout){
layout = _layout;
}
where QtGuiPDLVisitor is a c++ class exported in python using SWIG, so in python i want to do something like this
layout = QtGui.QGridLayout()
visitor = QtGuiPDLVisitor()
visitor.set_layout(layout)
is it possible? The python interpreter says no :(... is there any workaround, like a way of passing pointers or any other hack?
EDIT:
Traceback (most recent call last):
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pipeworkarea.py", line 53, in create_new_computation
subWindowWidget.setComputation(idx.data())
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pypeWidgets.py", line 44, in setComputation
self.widBuilder.buildUi(self)
File "/home/picci/workspace/gestface/pypelab/src/pypelab/ui/pypeWidgets.py", line 63, in buildUi
pdlVisitor.set_layout(criteria_area_layout)
File "/home/picci/workspace/gestface/pipeit/wrap/python/dist/Debug/pipeit.py", line 736, in set_layout
def set_layout(self, *args) -> "void" : return _pipeit.QtGuiPDLVisitor_set_layout(self, *args)
TypeError: in method 'QtGuiPDLVisitor_set_layout', argument 2 of type 'QLayout *'
This is the error from python. I already know that this error is due to the fact that Qt4 is wrapper in python using SIP, while i'm using SWIG to wrap, but i think that there must be a way to access directly to the pointer of the Qlayout object and pass it to C++ code from python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我实际上找到了一种方法来做到这一点。我
从 python 中使用,而不是在 c++ 中
使用,并且工作正常!
这里 sip doc 了解有关 sip.unwrapinstance() 的更多信息
Ok i actually find a way to do that. I used
from python, and than in c++
and worked!
here sip doc for more about sip.unwrapinstance()