Pankaj Lal
Pankaj Lal

Reputation: 317

QML not receiving the correct value from slot in pyside

I am looking to use the value returned by this function in a QAbstractListModel to create a ListView

@QtCore.Slot(int, result=QtCore.QAbstractListModel)
def subModel(self,index):
    print self._items[index]._plm()
    return self._items[index]._plm()

Following is my qml

                ListView {
                    id: progressList
                    model: tabsModel.subModel(index)
                    delegate: Component {
                          Item {
                                height: 42
                                width: 0.9*parent.width
                                Rectangle {
                                    height: parent.height
                                    width: parent.width*0.98
                                    x: 30
                                    y: 60
                                    color: "blue"
                                    Text {
                                        id: file_descr
                                        text: model.transfer.mfilename
                                        wrapMode: Text.WordWrap
                                        font.italic: true
                                        font.pointSize: 12
                                        clip:true
                                        color: "darkgrey"
                                        anchors.verticalCenter: parent.verticalCenter
                                        anchors.margins: 10
                                    }                                        
                                }                                    
                            }
                        }
                    }

I see that subModel gets called (the print statement is executed). But the model assignment does not happen in QML. I need to make this function (subModel) call to assign the model as it is a sub list. Where am I going wrong ?

I suspect some issue with result = QtCore.QAbstractListModel. I have played around by making it ProgressListModel (my actual ListModel class) but that also doesn't work.

Upvotes: 2

Views: 80

Answers (1)

Pankaj Lal
Pankaj Lal

Reputation: 317

Using "QVariant" instead of the QAbstractListModel fixed the problem.

@QtCore.Slot(int, result="QVariant")
def subModel(self,index):
    print self._items[index]._plm()
    return self._items[index]._plm()

Upvotes: 1

Related Questions