[PyQt] pyqtSlot, getting "undefined" return values when called from qml javascript

Phil Thompson phil at riverbankcomputing.com
Sun Apr 29 15:47:17 BST 2012


On Sat, 28 Apr 2012 00:57:47 +0300, "Ville M. Vainio" <vivainio at gmail.com>
wrote:
> I have a qml file invoking methods on a QObject subclass. I have used
> @pyqtSlot decorator to expose the methods as slots.
> 
> I can see that the methods are run; however, the return values seem to
> be discarded.
> 
> Code for the QObject subclass (that I expose with setContextProperty)
> is like this:
> 
> ===
> from PyQt4 import QtCore
> from PyQt4.QtCore import QObject,pyqtSlot
> 
> class NodeWrapper(QObject):
>     def __init__(self, c,v):
>         QObject.__init__(self)
> 
>         self.c = c
>         self.v = v
> 
>     @pyqtSlot()
>     def get_b(self):
>         return 2
>         #return self.v.b
>     @pyqtSlot()
>     def get_h(self):
>         return self.v.h
>     @pyqtSlot()
>     def children(self):
>         #self.all = all = [NodeWrapper(self.c, chi) for chi in
>         self.v.children]
>         all = "hello"
>         print "Will ret",all
>         return all
> 
> ===
> 
> I have tried passing return value in the decorator (return=int...).
> 
> Any clues where to look?

Have you got a complete test that demonstrates the problem?

Phil


More information about the PyQt mailing list