I've looked around on this forum and the web in general and have not found a clear discussion of using smart pointers with Qt objects. I am surprised to see most Qt examples using standard pointers. Does Qt perform some garbage collection?
Example:
QWidget * foo;
foo = new QWidget();
foo = new QWidget();
To copy to clipboard, switch view to plain text mode
Will the first object float around in memory or be cleaned up?
If it's a leak, should I instead use something like Boost's shared_ptr:
shared_ptr<QWidget> foo;
foo
= shared_ptr<QWidget>
(new QWidget());
foo
= shared_ptr<QWidget>
(new QWidget());
shared_ptr<QWidget> foo;
foo = shared_ptr<QWidget>(new QWidget());
foo = shared_ptr<QWidget>(new QWidget());
To copy to clipboard, switch view to plain text mode
I apologize if this question is ignorant of the underlying Qt design and/or has been answered thoroughly elsewhere on the forum.
Bookmarks