Is there safely about QScopedPointer?
-
Hi guys,
consider following code of class Bar
class Bar : QWidget { public: Bar(QWidget* w, ...) : widget_(w) { ... } void Foo() { if (widget_) { widget_->setParent(this); } // take ownership } private: QScopedPointer<QWidget, QScopedPointerObjectDeleteLater<QWidget>> widget_; // some external widget from another library }What about deletion flow of widget_? Is there wrong code?
-
@Alexey-Serebryakov said in Is there safely about QScopedPointer?:
Is there wrong code?
Yes because of parent-child QObject relationship. Rule of thumb: don't use auto-pointers with QObject derived classes.
-
Ah, exactly! Thank you so much.