How pass pointer from python to cpp
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Hello
I have problem with c function pointer wrapping. I have a c function that one of its argument is int pointer. so how can I pass pointer from python to it?
You can't. You could change the interface to take a QVector or QList of ints. The any sequence in Python will be converted to that list/vector.
thanks, I want a way that each value change of variable in cpp function also applies to python. is there any way to do that?
Hm, there are various ways, but all require some work, especially if you want to be able to modify the data from both sides...
Maybe the easiest would be to use a Python array (see standard library) of the desired type. But PythonQt does not support automatic conversion, so you would need to use a PyObject pointer in your slot and use the Python C api to talk to it from C++.
Another common way is to use numpy arrays, but that will require the numpy installation and you would need to use the numpy C api to get acces to the data in the C++ slot (also with a PyObject)
And another way is to return a Python memory view and use that as a buffer for an aary or numpy array.
But all these methods require deep understanding on what you are doing...keeping the ref counts correct etc.
thanks for helping