I already found and edited the answer below.
I want to return values ββfrom python code to javascript context in QtWebKit. So far I have this class:
class Extensions(QtCore.QObject): @QtCore.pyqtSlot() def constant_one(self): return 1;
I can call this function from Javascript as follows:
var a = extensions.constant_one();
and it really is called (I checked with print there); but still ends up undefined. Why doesn't it get the value returned by the function? I also tried wrapping a in QVariant, but still no dice.
Edit: I found the answer. Obviously, QtWebKit needs a result type as a hint. You can provide this with pyqtSlot-Decorator, for example:
class Extensions(QtCore.QObject): @QtCore.pyqtSlot(result="int") def constant_one(self): return 1;
and then it works correctly. Leaving it open for another two days if someone finds something else that I should do.
qt pyqt qtwebkit
CONTRACT SAYS I'M RIGHT
source share