[PyQt] wrapped C/C++ object of type has been deleted - yet it hasn't!

Kyle Altendorf sda at fstab.net
Tue Jul 25 13:19:51 BST 2017

Sorry for the repeat Nyall, I missed the list on my first reply.

On 2017-07-25 03:04, Nyall Dawson wrote:
> class MyClass
> {
>   public:
>     MyClass() {}
>     MyClass *create() const
>     {
>           MyClass * newInstance = createInstance();
>           // do some common stuff to newInstance here
>           return newInstance;
>      }
>   protected:
>     virtual MyClass *createInstance() const = 0;
> };

Disclaimer: I don't know SIP but this looks a bit weird by my 
recollection of C++ and current Python knowledge.

Is create() supposed to be static?  Or do you call it on an existing 
instance of MyClass and it uses aspects of the existing class for the 
'stuff' portion?

> class x(MyClass):
>     def __init__(self):
>         MyClass.__init__(self)
>     def createInstance(self):
>         new = x()
>         return new

Depending on the answer above I might expect createInstance() to be an 
@classmethod.  Also, what about the common stuff done in MyClass that's 
getting skipped?  Maybe super().createInstance() and then tweak the 
object and return it.

Alternatively, just make it a regular function (not a method) in both 
cases if it's not actually doing anything with an existing instance of 
MyClass/x (but still call the 'parent' function I would think).

Perhaps these would all be non-questions in the real code but the given 
example looks a bit off to me.  Best of luck resolving the issue.


More information about the PyQt mailing list