diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-24 22:06:09 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-16 05:19:04 +0000 |
commit | 70c624d93ee040e8aa4ab576be008f07bbfb8a2e (patch) | |
tree | e2666cc681dc1f42da422a383b00bd3a9892e9ed /src/widgets/kernel | |
parent | 45c5cc619933d1283da27a15d5d7ab3d2e8e5329 (diff) |
QWidget: replace manual memory management with unique_ptr [5/N]: extra->topextra
It is a bit frustrating that all the initialization and cleanup code
are not in the QTLWExtra ctor and dtor. But that is for another patch.
Change-Id: I0e45f89c1a53eb2f9a5699d3fbbef1a628b55432
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 5 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget_p.h | 6 |
2 files changed, 5 insertions, 6 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index aa93ee6be2..ba9b2a0487 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -1785,7 +1785,8 @@ void QWidgetPrivate::createTLExtra() if (!extra) createExtra(); if (!extra->topextra) { - QTLWExtra* x = extra->topextra = new QTLWExtra; + extra->topextra = qt_make_unique<QTLWExtra>(); + QTLWExtra* x = extra->topextra.get(); x->backingStore = 0; x->sharedPainter = 0; x->incw = x->inch = 0; @@ -1820,7 +1821,6 @@ void QWidgetPrivate::createExtra() if (!extra) { // if not exists extra = new QWExtra; extra->glContext = 0; - extra->topextra = 0; #if QT_CONFIG(graphicsview) extra->proxyWidget = 0; #endif @@ -1866,7 +1866,6 @@ void QWidgetPrivate::deleteExtra() if (extra->topextra) { deleteTLSysExtra(); // extra->topextra->backingStore destroyed in QWidgetPrivate::deleteTLSysExtra() - delete extra->topextra; } delete extra; // extra->xic destroyed in QWidget::destroy() diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h index 03b09f2ca8..c851072c11 100644 --- a/src/widgets/kernel/qwidget_p.h +++ b/src/widgets/kernel/qwidget_p.h @@ -239,7 +239,7 @@ struct QWExtra { // Regular pointers (keep them together to avoid gaps on 64 bits architectures). void *glContext; // if the widget is hijacked by QGLWindowSurface - QTLWExtra *topextra; // only useful for TLWs + std::unique_ptr<QTLWExtra> topextra; // only useful for TLWs #if QT_CONFIG(graphicsview) QGraphicsProxyWidget *proxyWidget; // if the widget is embedded #endif @@ -993,12 +993,12 @@ inline QWExtra *QWidgetPrivate::extraData() const inline QTLWExtra *QWidgetPrivate::topData() const { const_cast<QWidgetPrivate *>(this)->createTLExtra(); - return extra->topextra; + return extra->topextra.get(); } inline QTLWExtra *QWidgetPrivate::maybeTopData() const { - return extra ? extra->topextra : nullptr; + return extra ? extra->topextra.get() : nullptr; } inline QPainter *QWidgetPrivate::sharedPainter() const |