diff --git a/src/widgets/widgets/qeffects.cpp b/src/widgets/widgets/qeffects.cpp index 74ac24a2b0a..50c09ec4daf 100644 --- a/src/widgets/widgets/qeffects.cpp +++ b/src/widgets/widgets/qeffects.cpp @@ -19,6 +19,15 @@ QT_BEGIN_NAMESPACE +struct DeleteLater +{ + void operator()(QObject *o) const + { + if (o) + o->deleteLater(); + } +}; + /* Internal class QAlphaWidget. @@ -58,7 +67,7 @@ private: QElapsedTimer checkTime; }; -static QAlphaWidget* q_blend = nullptr; +static std::unique_ptr q_blend; /* Constructs a QAlphaWidget. @@ -227,8 +236,7 @@ void QAlphaWidget::render() anim.stop(); qApp->removeEventFilter(this); widget->setWindowOpacity(1); - q_blend = 0; - deleteLater(); + q_blend.reset(); } else { widget->setWindowOpacity(alpha); } @@ -248,8 +256,7 @@ void QAlphaWidget::render() lower(); } } - q_blend = nullptr; - deleteLater(); + q_blend.reset(); } else { alphaBlend(); pm = QPixmap::fromImage(mixedImage); @@ -341,7 +348,7 @@ private: QPixmap pm; }; -static QRollEffect* q_roll = nullptr; +static std::unique_ptr q_roll; /* Construct a QRollEffect widget. @@ -513,8 +520,7 @@ void QRollEffect::scroll() lower(); } } - q_roll = nullptr; - deleteLater(); + q_roll.reset(); } } @@ -524,10 +530,7 @@ void QRollEffect::scroll() */ void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) { - if (q_roll) { - q_roll->deleteLater(); - q_roll = nullptr; - } + q_roll.reset(); if (!w) return; @@ -537,7 +540,7 @@ void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) Qt::WindowFlags flags = Qt::ToolTip; // those can be popups - they would steal the focus, but are disabled - q_roll = new QRollEffect(w, flags, orient); + q_roll.reset(new QRollEffect(w, flags, orient)); q_roll->run(time); } @@ -546,10 +549,7 @@ void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) */ void qFadeEffect(QWidget* w, int time) { - if (q_blend) { - q_blend->deleteLater(); - q_blend = nullptr; - } + q_blend.reset(); if (!w) return; @@ -560,7 +560,7 @@ void qFadeEffect(QWidget* w, int time) Qt::WindowFlags flags = Qt::ToolTip; // those can be popups - they would steal the focus, but are disabled - q_blend = new QAlphaWidget(w, flags); + q_blend.reset(new QAlphaWidget(w, flags)); q_blend->run(time); }