如何将对象从 python 返回到 QML?
我正在尝试从插槽返回 QObject。我正在使用 PySide 和 QML。我的代码如下所示:
class myClass(QtCore.QObject):
def __init__(self):
self.object = QtCore.QObject()
QtCore.Slot(result=object)
def myFunc(self):
return self.object
当我 console.log 时,我得到的返回值:
QVariant(PySide::PyObjectWrapper)
我似乎无法从这个东西中获取值。有人能指出我正确的方向吗?我可以返回原始类型(如 int、str 等),但对象、列表和字典超出了我的范围。任何帮助将不胜感激。
编辑
我正在尝试使用点表示法访问对象的属性。如果有人能给我举一个例子,那将会非常有帮助。不过,如果我能把东西拿回来,我想我可以自己走完这段距离。再次感谢!
谢谢杰克
I'm trying to return a QObject from a Slot. I'm using PySide and QML. My code looks like this:
class myClass(QtCore.QObject):
def __init__(self):
self.object = QtCore.QObject()
QtCore.Slot(result=object)
def myFunc(self):
return self.object
When I console.log the return value I get:
QVariant(PySide::PyObjectWrapper)
I can't seem to get the value out of this thing. Can somebody point me in the right direction? I can return primitive types (like int, str, etc.), but objects, lists, and dicts are beyond me. Any help would be greatly appreciated.
EDIT
I am trying to access properties of an object using dot notation. If somebody could show me an example of this, it would be very helpful. However, if I could just get the object back I think I could go the distance by myself. Thanks again!
Thanks
Jack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,这就是我认为你想要做的事情。当您单击任意位置时,蓝色区域会变为绿色。这是通过更改信号传递的对象的颜色属性来完成的。
使用随附的 qml 文件(我将其称为 pass_an_object.qml):
So, here is something that does what I think you're trying to do. When you click anywhere, the blue area changes green. This is done by changing the color property on the object that is passed by a signal.
With the accompanying qml file (I've called it pass_an_object.qml):