Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyqtSlot() and return type python list

Tags:

python

pyqt

I need to use pyqtSlot() decorator in order to expose a python function to javascript code.
The return type is list so i should write:
@pyqtSlot(result=list)
But i get an error:
"TypeError: unable to convert a Python 'list' object to a C++ 'PyQt_PyObject' instance"

I made some research but yet couldnt find an answer.
According to pyqt doc i can return any python type object or a string specifying a C++ type, so i tried result='array'.
But it doesnt work or i do something wrong.

@pyqtSlot(result=list)
def getCodeList(self):
    return self.codeList
like image 605
Alon Lavi Avatar asked May 06 '14 20:05

Alon Lavi


1 Answers

I think i found a way.
I just wrap python list with QVariant() and return QVariant.

@pyqtSlot(result=QVariant)
def getCodeList(self):
    return QVariant(self.codeList)

Thanks QVariant.

like image 152
Alon Lavi Avatar answered Nov 15 '22 00:11

Alon Lavi