[Interest] What's the recommended way to put QObjects in smart pointers?
Jean-Michaƫl Celerier
jeanmichael.celerier at gmail.com
Thu May 5 12:15:47 CEST 2016
On Thu, May 5, 2016 at 3:24 AM, Nikos Chantziaras <realnc at gmail.com> wrote:
>
> By now, I consider application-level code that uses 'new' or 'delete' as
> bogus and in need of fixing.
This line of thought doesn't work at all with Qt. It's just how it is done
<http://doc.qt.io/qt-5/object.html>. If you are in such dire need of
guaranteeing the absence of memory problems :
template<typename T, typename... Args>
auto make_qobject(Args&&... args, QObject* parent) // Repeat for
QGraphicsItem / Object if necessary
{
assert(parent);
return new T{std::forward<Args>(args)..., parent};
}
QMainWindow win;
auto safe_obj_1 = make_qobject<QListWidget> (&win);
auto safe_obj_2 = make_qobject<QGridView>(&win);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160505/50032f35/attachment.html>
More information about the Interest
mailing list