[PySide] What can be returned from a slot?

Yosef Meller yosefmel at post.tau.ac.il
Sun Jan 13 10:46:23 CET 2013


I'm trying to follow the selectable list example on the wiki,
http://qt-project.org/wiki/Selectable-list-of-Python-objects-in-QML

but instead of returning a QObject-wrapped Python object, I'm trying to return 
a Python class deriving from QAbstractListModel. However, when I console.log 
the returned object, I get 'undefined'.

I don't know exactly where my problem is but I suspect that a signal can only 
return a certain types of things, because when I return 'int' the int is 
returned fine. So what  can I return from a slot, and how can I expand it to 
return my model?


My list model looks like this:

class TargetListModel(QtCore.QAbstractListModel):
    def __init__(self, targets):
        QtCore.QAbstractListModel.__init__(self)
        self._targets = targets
        self.setRoleNames({0: 'posx', 1: 'posy'})

    def rowCount(self, parent=QtCore.QModelIndex()):
        return len(self._targets)

    def data(self, index, role):
        if not index.isValid():
            return

        target = self._targets[index.row()]
        if role == 0:
            return target['x']
        elif role == 1:
            return target['y']

And I return it from a slot like this:
class ImageExplorer(QtCore.QObject):
    @QtCore.Slot(int, int, result=object)
    def image_targets(self, frame, cam):
        return TargetListModel([
            {'x': 100, 'y': 100},
            {'x': 200, 'y': 200},
        ])

Thanks in advance for any tip,
Yosef.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130113/3a7d9e72/attachment.html>


More information about the PySide mailing list