PythonQtObjectPtr::evalScript() question
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hi, I'm having trouble getting a value returned from evalScript(). I have the following C++ code:
and Python code:
the returned PythonQtObjectPtr always has a 0 pointer in it. However, if I change the Python code to:
and C++ to:
I get a good PythonQtObjectPtr. Shouldn't evalScript() return the value of the function call in the first case? I also tried capturing the function result in a module variable prior to returning the function result, in case of refCount issues, but same error.
Any suggestions, I'd rather not use that thread-unsafe hack?
Thanks,
John.
You need to pass Py_eval_input as second parameter to evalScript(). Note that then you can only pass a single expression as source code.
The reason is that Python code does not automatically return the last value as its result, only expressions do that.
Alternatively, you can do:
to call the method and get the result.
OK, thanks Florian, that fixed it!