5

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
2

1 Answer 1

9

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.

2
  • how you convert QVariant into list later?
    – Aleksandar
    May 13, 2014 at 10:45
  • 1
    i dont need to convert.it just works. but if i'll try to understand why according my little knowledge.. pyqtSlot decorator is made in order to pass result into C++ which is the language Qt is written in. so list type in python is turned to an array type of C++ using QVariant. and all that is made so QtWebkit bridge technology can expose code written in C++(or python using decorator pyqtSlot) to javascript code. all what i wrote is not 100% sure. so take it with caution.
    – Alon Lavi
    Jun 2, 2014 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.