Smart pointers with QT memory model

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Smart pointers with QT memory model

Post by abdullah »

I have this code from stackoverflow in NotificationBox.cpp, which basically is to use smart pointers with a custom destructor for the QT memory model.

Now there are more places where I would like to use it, so I am aiming at moving it to a better-place(tm). Own header, part of an existing header? Any preferences of suggestions?

Code: Select all

// https://stackoverflow.com/questions/41402152/stdunique-ptr-and-qobjectdeletelater
struct QObjectDeleteLater
{
    void operator()(QObject* o)
    {
        o->deleteLater();
    }
};

template<typename T>
using qobject_delete_later_unique_ptr = std::unique_ptr<T, QObjectDeleteLater>;
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Smart pointers with QT memory model

Post by openBrain »

I wonder if this hasn't been already used somewhere on FC. With a mobile now but I'll search later on.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Smart pointers with QT memory model

Post by openBrain »

Well, now had a search and didn't found. :|
Let's say it's fine as it is. :)
Post Reply