Using a custom shared_ptr class, recommendations?
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
I'm working on a library that requires the use of a special shared_ptr class, currently I'm trying to make a custom object wrapper for that class.
The wrapper looks like this:
and I register it like this:
Everything works correctly for accessing values, except delete_NodePtr is not called when I delete an object from inside of python.
I'm using PythonQt from (https://github.com/Orochimarufan/PythonQt) and particularly the PyCPPWrapperExample.
Any tips on fixing this?
[edit]
I should clarify that the shared pointer object is returned from a function in an object that is wrapped as follows:
Last edit: Dan 2016-05-11
Hm, returning a pointer to a shared_ptr sound a bit fishy... You should probably return just a shared_ptr, without the star. I am also a bit confused by your naming. Shouldn't you typedef rcc::shared_ptr<EagleLib::Nodes::Node> to NodePtr and then use NodePtr* in your API? I don't see how the moc could understand that rcc::shared_ptr<EagleLib::Nodes::Node> is supposed to be a NodePtr... Regarding the delete, since you register your type as QMetaType, PythonQt probably calls the delete/destroy call on the QMetaType instead of your delete slot. But first I would try the typedef and use NodePtr throughout your API.
Hello and thank you for your response.
I forgot that I tried that previously, but for sake of testing I'm willing to look at it again, maybe you can help me figure out what I did wrong.
So I've typedefed as follows:
I then have a class member function which returns a shared_ptr object:
Now in python I can get the node which returns a NodePtr object:
But when I try to access it, I get a read access violation:
Which is in the object's copy constructor.
Which is called from this function:
Btw this is the new definition of NodeWrapper:
Last edit: Dan 2016-05-14
In your class wrapper, you need to use a pointer to your typedef.
and the same in all call arguments. This is the calling convention that
PythonQt uses for wrapper slots.
Regards,
Florian
On Saturday, 14 May 2016, Dan percocetpenguin@users.sf.net wrote: