From dfa7907c5205730a529a03ca6d7fa527f2b00d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Fri, 4 Mar 2022 12:28:49 +0100 Subject: Fix deprecated uses of QScopedPointer By changing it to unique_ptr. Change-Id: I91abb69445b537d4c95983ae735341882352b29d Reviewed-by: Marc Mutz Reviewed-by: Thiago Macieira (cherry picked from commit 034d8898f8166423db085da529787e56204c8e15) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qcoreapplication.cpp | 23 +++++++++-------- src/corelib/kernel/qmetaobject.cpp | 5 ++-- src/corelib/kernel/qobject.cpp | 5 ++-- src/corelib/thread/qthreadpool.cpp | 9 ++++--- src/gui/image/qbitmap.cpp | 6 +++-- src/gui/image/qimage.cpp | 6 +++-- src/gui/image/qpixmap.cpp | 14 ++++++----- src/gui/itemmodels/qfilesystemmodel.cpp | 4 +-- src/gui/painting/qpaintengine.cpp | 9 ++++--- src/gui/painting/qpainter.cpp | 12 ++++++--- src/gui/painting/qpainter.h | 3 ++- src/gui/painting/qpainter_p.h | 2 +- src/gui/painting/qregion.cpp | 5 ++-- src/gui/rhi/qrhi.cpp | 8 +++--- src/gui/text/freetype/qfontengine_ft.cpp | 29 ++++++++++++---------- src/gui/text/freetype/qfontengine_ft_p.h | 1 - src/gui/text/qzip.cpp | 14 ++++++----- .../access/qhttpnetworkconnectionchannel.cpp | 24 ++++++++++-------- .../access/qhttpnetworkconnectionchannel_p.h | 4 ++- src/network/socket/qsocks5socketengine.cpp | 6 +++-- src/opengl/qopenglengineshadermanager.cpp | 13 +++++----- src/opengl/qopenglshaderprogram.cpp | 5 ++-- src/openglwidgets/qopenglwidget.cpp | 4 +-- .../platforms/windows/qwindowsintegration.cpp | 10 +++++--- src/testlib/qtestcase.cpp | 17 +++++++------ src/xml/dom/qdomhelpers.cpp | 15 +++++------ 26 files changed, 144 insertions(+), 109 deletions(-) (limited to 'src') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 25fdc5b546..af0be3ff75 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -134,6 +134,7 @@ #endif #include +#include QT_BEGIN_NAMESPACE @@ -391,8 +392,8 @@ struct QCoreApplicationData { bool applicationVersionSet; // true if setApplicationVersion was called #if QT_CONFIG(library) - QScopedPointer app_libpaths; - QScopedPointer manual_libpaths; + std::unique_ptr app_libpaths; + std::unique_ptr manual_libpaths; #endif }; @@ -568,7 +569,7 @@ void QCoreApplicationPrivate::checkReceiverThread(QObject *receiver) void QCoreApplicationPrivate::appendApplicationPathToLibraryPaths() { #if QT_CONFIG(library) - QStringList *app_libpaths = coreappdata()->app_libpaths.data(); + QStringList *app_libpaths = coreappdata()->app_libpaths.get(); if (!app_libpaths) coreappdata()->app_libpaths.reset(app_libpaths = new QStringList); QString app_location = QCoreApplication::applicationFilePath(); @@ -815,8 +816,8 @@ void QCoreApplicationPrivate::init() // Reset the lib paths, so that they will be recomputed, taking the availability of argv[0] // into account. If necessary, recompute right away and replay the manual changes on top of the // new lib paths. - QStringList *appPaths = coreappdata()->app_libpaths.take(); - QStringList *manualPaths = coreappdata()->manual_libpaths.take(); + QStringList *appPaths = coreappdata()->app_libpaths.release(); + QStringList *manualPaths = coreappdata()->manual_libpaths.release(); if (appPaths) { if (manualPaths) { // Replay the delta. As paths can only be prepended to the front or removed from @@ -1612,10 +1613,10 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority) // delete the event on exceptions to protect against memory leaks till the event is // properly owned in the postEventList - QScopedPointer eventDeleter(event); + std::unique_ptr eventDeleter(event); Q_TRACE(QCoreApplication_postEvent_event_posted, receiver, event, event->type()); data->postEventList.addEvent(QPostEvent(receiver, event, priority)); - eventDeleter.take(); + Q_UNUSED(eventDeleter.release()); event->m_posted = true; ++receiver->d_func()->postedEvents; data->canWait = false; @@ -2868,14 +2869,14 @@ void QCoreApplication::addLibraryPath(const QString &path) QMutexLocker locker(libraryPathMutex()); - QStringList *libpaths = coreappdata()->manual_libpaths.data(); + QStringList *libpaths = coreappdata()->manual_libpaths.get(); if (libpaths) { if (libpaths->contains(canonicalPath)) return; } else { // make sure that library paths are initialized libraryPathsLocked(); - QStringList *app_libpaths = coreappdata()->app_libpaths.data(); + QStringList *app_libpaths = coreappdata()->app_libpaths.get(); if (app_libpaths->contains(canonicalPath)) return; @@ -2907,14 +2908,14 @@ void QCoreApplication::removeLibraryPath(const QString &path) QMutexLocker locker(libraryPathMutex()); - QStringList *libpaths = coreappdata()->manual_libpaths.data(); + QStringList *libpaths = coreappdata()->manual_libpaths.get(); if (libpaths) { if (libpaths->removeAll(canonicalPath) == 0) return; } else { // make sure that library paths is initialized libraryPathsLocked(); - QStringList *app_libpaths = coreappdata()->app_libpaths.data(); + QStringList *app_libpaths = coreappdata()->app_libpaths.get(); if (!app_libpaths->contains(canonicalPath)) return; diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 19c437a4ec..91cb5e1369 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -62,6 +62,7 @@ #include "private/qmetaobject_moc_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -2399,7 +2400,7 @@ bool QMetaMethod::invoke(QObject *object, return false; } - QScopedPointer event(new QMetaCallEvent(idx_offset, idx_relative, callFunction, nullptr, -1, paramCount)); + auto event = std::make_unique(idx_offset, idx_relative, callFunction, nullptr, -1, paramCount); QMetaType *types = event->types(); void **args = event->args(); @@ -2423,7 +2424,7 @@ bool QMetaMethod::invoke(QObject *object, } } - QCoreApplication::postEvent(object, event.take()); + QCoreApplication::postEvent(object, event.release()); } else { // blocking queued connection #if QT_CONFIG(thread) if (receiverInSameThread) { diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 4968782847..09b68f0943 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -71,6 +71,7 @@ #include #include +#include #include #include @@ -125,7 +126,7 @@ static int *queuedConnectionTypes(const QMetaMethod &method) static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc) { - QScopedArrayPointer types(new int[argc + 1]); + auto types = std::make_unique(argc + 1); for (int i = 0; i < argc; ++i) { const QArgumentType &type = argumentTypes[i]; if (type.type()) @@ -145,7 +146,7 @@ static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc) } types[argc] = 0; - return types.take(); + return types.release(); } static QBasicMutex _q_ObjectMutexPool[131]; diff --git a/src/corelib/thread/qthreadpool.cpp b/src/corelib/thread/qthreadpool.cpp index 94b0aff451..fee6354b0a 100644 --- a/src/corelib/thread/qthreadpool.cpp +++ b/src/corelib/thread/qthreadpool.cpp @@ -43,6 +43,7 @@ #include "qcoreapplication.h" #include +#include QT_BEGIN_NAMESPACE @@ -274,16 +275,16 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const void QThreadPoolPrivate::startThread(QRunnable *runnable) { Q_ASSERT(runnable != nullptr); - QScopedPointer thread(new QThreadPoolThread(this)); + auto thread = std::make_unique(this); if (objectName.isEmpty()) objectName = QLatin1String("Thread (pooled)"); thread->setObjectName(objectName); - Q_ASSERT(!allThreads.contains(thread.data())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here) - allThreads.insert(thread.data()); + Q_ASSERT(!allThreads.contains(thread.get())); // if this assert hits, we have an ABA problem (deleted threads don't get removed here) + allThreads.insert(thread.get()); ++activeThreads; thread->runnable = runnable; - thread.take()->start(threadPriority); + thread.release()->start(threadPriority); } /*! diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index e2abb935e7..d60ea2b56b 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -46,6 +46,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE /*! @@ -189,10 +191,10 @@ static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags) image.setColor(1, c0); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType)); data->fromImageInPlace(image, flags | Qt::MonoOnly); - return QBitmap::fromPixmap(QPixmap(data.take())); + return QBitmap::fromPixmap(QPixmap(data.release())); } /*! diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 1ed94f70e2..a4743bff4d 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -77,6 +77,8 @@ #include +#include + QT_BEGIN_NAMESPACE // MSVC 19.28 does show spurious warning "C4723: potential divide by 0" for code that divides @@ -140,7 +142,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format) if (!params.isValid()) return nullptr; - QScopedPointer d(new QImageData); + auto d = std::make_unique(); switch (format) { case QImage::Format_Mono: @@ -168,7 +170,7 @@ QImageData * QImageData::create(const QSize &size, QImage::Format format) return nullptr; d->ref.ref(); - return d.take(); + return d.release(); } QImageData::~QImageData() diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 4bfdbd9253..89fd62305b 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -68,6 +68,8 @@ #include +#include + QT_BEGIN_NAMESPACE // MSVC 19.28 does show spurious warning "C4723: potential divide by 0" for code that divides @@ -1479,9 +1481,9 @@ QPixmap QPixmap::fromImage(const QImage &image, Qt::ImageConversionFlags flags) return QPixmap(); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImage(image, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! @@ -1506,9 +1508,9 @@ QPixmap QPixmap::fromImageInPlace(QImage &image, Qt::ImageConversionFlags flags) return QPixmap(); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageInPlace(image, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! @@ -1530,9 +1532,9 @@ QPixmap QPixmap::fromImageReader(QImageReader *imageReader, Qt::ImageConversionF return QPixmap(); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->fromImageReader(imageReader, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! diff --git a/src/gui/itemmodels/qfilesystemmodel.cpp b/src/gui/itemmodels/qfilesystemmodel.cpp index 0ee97d06be..ad27e0e5a0 100644 --- a/src/gui/itemmodels/qfilesystemmodel.cpp +++ b/src/gui/itemmodels/qfilesystemmodel.cpp @@ -907,14 +907,14 @@ bool QFileSystemModel::setData(const QModelIndex &idx, const QVariant &value, in int visibleLocation = parentNode->visibleLocation(parentNode->children.value(indexNode->fileName)->fileName); parentNode->visibleChildren.removeAt(visibleLocation); - QScopedPointer nodeToRename(parentNode->children.take(oldName)); + std::unique_ptr nodeToRename(parentNode->children.take(oldName)); nodeToRename->fileName = newName; nodeToRename->parent = parentNode; #if QT_CONFIG(filesystemwatcher) nodeToRename->populate(d->fileInfoGatherer.getInfo(QFileInfo(parentPath, newName))); #endif nodeToRename->isVisible = true; - parentNode->children[newName] = nodeToRename.take(); + parentNode->children[newName] = nodeToRename.release(); parentNode->visibleChildren.insert(visibleLocation, newName); d->delayedSort(); diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp index 9b0ec446ff..db84b20d06 100644 --- a/src/gui/painting/qpaintengine.cpp +++ b/src/gui/painting/qpaintengine.cpp @@ -52,6 +52,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -1009,9 +1010,9 @@ QPixmap QPaintEngine::createPixmap(QSize size) return QPixmap(); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); data->resize(size.width(), size.height()); - return QPixmap(data.take()); + return QPixmap(data.release()); } /*! @@ -1026,12 +1027,12 @@ QPixmap QPaintEngine::createPixmapFromImage(QImage image, Qt::ImageConversionFla return QPixmap(); } - QScopedPointer data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); + std::unique_ptr data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType)); if (image.isDetached()) data->fromImageInPlace(image, flags); else data->fromImage(image, flags); - return QPixmap(data.take()); + return QPixmap(data.release()); } QPaintEnginePrivate::~QPaintEnginePrivate() diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index f1b02f3e9b..704b841b15 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ // QtCore +#include #include #include #include @@ -77,6 +78,9 @@ QT_BEGIN_NAMESPACE +// We changed the type from QScopedPointer to unique_ptr, make sure it's binary compatible: +static_assert(sizeof(QScopedPointer) == sizeof(std::unique_ptr)); + #define QGradient_StretchToDevice 0x10000000 #define QPaintEngine_OpaqueBackground 0x40000000 @@ -276,9 +280,9 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) // the current d_ptr to the shared painter's d_ptr. sp->save(); ++sp->d_ptr->refcount; - sp->d_ptr->d_ptrs.push_back(q->d_ptr.data()); - q->d_ptr.take(); - q->d_ptr.reset(sp->d_ptr.data()); + sp->d_ptr->d_ptrs.push_back(q->d_ptr.get()); + Q_UNUSED(q->d_ptr.release()); + q->d_ptr.reset(sp->d_ptr.get()); Q_ASSERT(q->d_ptr->state); @@ -333,7 +337,7 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q) } q->restore(); - q->d_ptr.take(); + Q_UNUSED(q->d_ptr.release()); q->d_ptr.reset(original); if (emulationEngine) { diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index 6446e88b0b..7c470ddae5 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -48,6 +48,7 @@ #include #include #include +#include #ifndef QT_INCLUDE_COMPAT #include @@ -448,7 +449,7 @@ public: private: Q_DISABLE_COPY(QPainter) - QScopedPointer d_ptr; + std::unique_ptr d_ptr; friend class QWidget; friend class QFontEngine; diff --git a/src/gui/painting/qpainter_p.h b/src/gui/painting/qpainter_p.h index 7f5fe1a6c5..6cf1846862 100644 --- a/src/gui/painting/qpainter_p.h +++ b/src/gui/painting/qpainter_p.h @@ -252,7 +252,7 @@ public: static QPainterPrivate *get(QPainter *painter) { - return painter->d_ptr.data(); + return painter->d_ptr.get(); } QTransform viewTransform() const; diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index 6ca87cb416..7a15174725 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -48,6 +48,7 @@ #include "qbitmap.h" #include "qtransform.h" +#include #include #ifdef Q_OS_WIN @@ -3915,7 +3916,7 @@ QRegion &QRegion::operator=(const QRegion &r) QRegion QRegion::copy() const { QRegion r; - QScopedPointer x(new QRegionData); + auto x = std::make_unique(); x->ref.initializeOwned(); if (d->qt_rgn) x->qt_rgn = new QRegionPrivate(*d->qt_rgn); @@ -3923,7 +3924,7 @@ QRegion QRegion::copy() const x->qt_rgn = new QRegionPrivate; if (!r.d->ref.deref()) cleanUp(r.d); - r.d = x.take(); + r.d = x.release(); return r; } diff --git a/src/gui/rhi/qrhi.cpp b/src/gui/rhi/qrhi.cpp index d8bd4536ae..cfca6f233c 100644 --- a/src/gui/rhi/qrhi.cpp +++ b/src/gui/rhi/qrhi.cpp @@ -55,6 +55,8 @@ #include "qrhimetal_p_p.h" #endif +#include + QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general") @@ -4975,7 +4977,7 @@ QRhi::~QRhi() */ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRhiNativeHandles *importDevice) { - QScopedPointer r(new QRhi); + std::unique_ptr r(new QRhi); switch (impl) { case Null: @@ -5023,7 +5025,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh } if (r->d) { - r->d->q = r.data(); + r->d->q = r.get(); if (flags.testFlag(EnableProfiling)) { QRhiProfilerPrivate *profD = QRhiProfilerPrivate::get(&r->d->profiler); @@ -5042,7 +5044,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh if (r->d->create(flags)) { r->d->implType = impl; r->d->implThread = QThread::currentThread(); - return r.take(); + return r.release(); } } diff --git a/src/gui/text/freetype/qfontengine_ft.cpp b/src/gui/text/freetype/qfontengine_ft.cpp index b24e620d15..c494c77e95 100644 --- a/src/gui/text/freetype/qfontengine_ft.cpp +++ b/src/gui/text/freetype/qfontengine_ft.cpp @@ -59,6 +59,8 @@ #include #include +#include + #include #include FT_FREETYPE_H #include FT_OUTLINE_H @@ -224,7 +226,8 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id, if (freetype) { freetype->ref.ref(); } else { - QScopedPointer newFreetype(new QFreetypeFace); + const auto deleter = [](QFreetypeFace *f) { delete f; }; + std::unique_ptr newFreetype(new QFreetypeFace, deleter); FT_Face face; if (!face_id.filename.isEmpty()) { QString fileName = QFile::decodeName(face_id.filename); @@ -293,13 +296,13 @@ QFreetypeFace *QFreetypeFace::getFace(const QFontEngine::FaceId &face_id, FT_Set_Charmap(newFreetype->face, newFreetype->unicode_map); QT_TRY { - freetypeData->faces.insert(face_id, newFreetype.data()); + freetypeData->faces.insert(face_id, newFreetype.get()); } QT_CATCH(...) { - newFreetype.take()->release(face_id); + newFreetype.release()->release(face_id); // we could return null in principle instead of throwing QT_RETHROW; } - freetype = newFreetype.take(); + freetype = newFreetype.release(); } return freetype; } @@ -594,7 +597,7 @@ static QFontEngine::SubpixelAntialiasingType subpixelAntialiasingTypeHint() QFontEngineFT *QFontEngineFT::create(const QFontDef &fontDef, FaceId faceId, const QByteArray &fontData) { - QScopedPointer engine(new QFontEngineFT(fontDef)); + auto engine = std::make_unique(fontDef); QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono; const bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias); @@ -616,7 +619,7 @@ QFontEngineFT *QFontEngineFT::create(const QFontDef &fontDef, FaceId faceId, con } engine->setQtDefaultHintStyle(static_cast(fontDef.hintingPreference)); - return engine.take(); + return engine.release(); } namespace { @@ -1075,7 +1078,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, } int glyph_buffer_size = 0; - QScopedArrayPointer glyph_buffer; + std::unique_ptr glyph_buffer; FT_Render_Mode renderMode = (default_hint_style == HintLight) ? FT_RENDER_MODE_LIGHT : FT_RENDER_MODE_NORMAL; switch (format) { case Format_Mono: @@ -1120,7 +1123,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) { uchar *src = slot->bitmap.buffer; - uchar *dst = glyph_buffer.data(); + uchar *dst = glyph_buffer.get(); int h = slot->bitmap.rows; // Some fonts return bitmaps even when we requested something else: if (format == Format_Mono) { @@ -1149,7 +1152,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, } else if (slot->bitmap.pixel_mode == 7 /*FT_PIXEL_MODE_BGRA*/) { Q_ASSERT(format == Format_ARGB); uchar *src = slot->bitmap.buffer; - uchar *dst = glyph_buffer.data(); + uchar *dst = glyph_buffer.get(); int h = slot->bitmap.rows; while (h--) { #if Q_BYTE_ORDER == Q_BIG_ENDIAN @@ -1169,7 +1172,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { Q_ASSERT(format == Format_A8); uchar *src = slot->bitmap.buffer; - uchar *dst = glyph_buffer.data(); + uchar *dst = glyph_buffer.get(); int h = slot->bitmap.rows; int bytes = info.width; while (h--) { @@ -1179,10 +1182,10 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, } } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) { Q_ASSERT(format == Format_A32); - convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB); + convertRGBToARGB(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_RGB); } else if (slot->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) { Q_ASSERT(format == Format_A32); - convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.data(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB); + convertRGBToARGB_V(slot->bitmap.buffer, (uint *)glyph_buffer.get(), info.width, info.height, slot->bitmap.pitch, subpixelType != Subpixel_VRGB); } else { qWarning("QFontEngine: Glyph rendered in unknown pixel_mode=%d", slot->bitmap.pixel_mode); return nullptr; @@ -1201,7 +1204,7 @@ QFontEngineFT::Glyph *QFontEngineFT::loadGlyph(QGlyphSet *set, uint glyph, g->advance = info.xOff; g->format = format; delete [] g->data; - g->data = glyph_buffer.take(); + g->data = glyph_buffer.release(); if (set) set->setGlyph(glyph, subPixelPosition, g); diff --git a/src/gui/text/freetype/qfontengine_ft_p.h b/src/gui/text/freetype/qfontengine_ft_p.h index 03059c7d13..f3ae6d8cad 100644 --- a/src/gui/text/freetype/qfontengine_ft_p.h +++ b/src/gui/text/freetype/qfontengine_ft_p.h @@ -117,7 +117,6 @@ public: private: friend class QFontEngineFT; friend class QtFreetypeData; - friend struct QScopedPointerDeleter; QFreetypeFace() = default; ~QFreetypeFace() {} void cleanup(); diff --git a/src/gui/text/qzip.cpp b/src/gui/text/qzip.cpp index 1fe7a6d042..0b1fe00779 100644 --- a/src/gui/text/qzip.cpp +++ b/src/gui/text/qzip.cpp @@ -48,6 +48,8 @@ #include #include +#include + #include // Zip standard version for archives handled by this API @@ -822,7 +824,7 @@ void QZipWriterPrivate::addEntry(EntryType type, const QString &fileName, const */ QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode) { - QScopedPointer f(new QFile(archive)); + auto f = std::make_unique(archive); const bool result = f->open(mode); QZipReader::Status status; const QFileDevice::FileError error = f->error(); @@ -839,8 +841,8 @@ QZipReader::QZipReader(const QString &archive, QIODevice::OpenMode mode) status = FileError; } - d = new QZipReaderPrivate(f.data(), /*ownDevice=*/true); - f.take(); + d = new QZipReaderPrivate(f.get(), /*ownDevice=*/true); + Q_UNUSED(f.release()); d->status = status; } @@ -1139,7 +1141,7 @@ void QZipReader::close() */ QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode) { - QScopedPointer f(new QFile(fileName)); + auto f = std::make_unique(fileName); QZipWriter::Status status; if (f->open(mode) && f->error() == QFile::NoError) status = QZipWriter::NoError; @@ -1154,8 +1156,8 @@ QZipWriter::QZipWriter(const QString &fileName, QIODevice::OpenMode mode) status = QZipWriter::FileError; } - d = new QZipWriterPrivate(f.data(), /*ownDevice=*/true); - f.take(); + d = new QZipWriterPrivate(f.get(), /*ownDevice=*/true); + Q_UNUSED(f.release()); d->status = status; } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 17c0acca57..34636f34f1 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -58,6 +58,8 @@ #include "private/qnetconmonitor_p.h" +#include + QT_BEGIN_NAMESPACE namespace @@ -242,7 +244,7 @@ void QHttpNetworkConnectionChannel::abort() bool QHttpNetworkConnectionChannel::sendRequest() { - Q_ASSERT(!protocolHandler.isNull()); + Q_ASSERT(protocolHandler); return protocolHandler->sendRequest(); } @@ -255,7 +257,7 @@ bool QHttpNetworkConnectionChannel::sendRequest() void QHttpNetworkConnectionChannel::sendRequestDelayed() { QMetaObject::invokeMethod(this, [this] { - Q_ASSERT(!protocolHandler.isNull()); + Q_ASSERT(protocolHandler); if (reply) protocolHandler->sendRequest(); }, Qt::ConnectionType::QueuedConnection); @@ -263,13 +265,13 @@ void QHttpNetworkConnectionChannel::sendRequestDelayed() void QHttpNetworkConnectionChannel::_q_receiveReply() { - Q_ASSERT(!protocolHandler.isNull()); + Q_ASSERT(protocolHandler); protocolHandler->_q_receiveReply(); } void QHttpNetworkConnectionChannel::_q_readyRead() { - Q_ASSERT(!protocolHandler.isNull()); + Q_ASSERT(protocolHandler); protocolHandler->_q_readyRead(); } @@ -478,18 +480,18 @@ void QHttpNetworkConnectionChannel::allDone() // trick with ProtocolHandlerDeleter, a QObject-derived class. // These dances below just make it somewhat exception-safe. // 1. Create a new owner: - QAbstractProtocolHandler *oldHandler = protocolHandler.data(); - QScopedPointer deleter(new ProtocolHandlerDeleter(oldHandler)); + QAbstractProtocolHandler *oldHandler = protocolHandler.get(); + auto deleter = std::make_unique(oldHandler); // 2. Retire the old one: - protocolHandler.take(); + Q_UNUSED(protocolHandler.release()); // 3. Call 'deleteLater': deleter->deleteLater(); // 3. Give up the ownerthip: - deleter.take(); + Q_UNUSED(deleter.release()); connection->fillHttp2Queue(); protocolHandler.reset(new QHttp2ProtocolHandler(this)); - QHttp2ProtocolHandler *h2c = static_cast(protocolHandler.data()); + QHttp2ProtocolHandler *h2c = static_cast(protocolHandler.get()); QMetaObject::invokeMethod(h2c, "_q_receiveReply", Qt::QueuedConnection); QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); // If we only had one request sent with H2 allowed, we may fail to send @@ -995,11 +997,11 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket // we do not resend, but must report errors if any request is in progress (note, while // not in its sendRequest(), protocol handler switches the channel to IdleState, thus // this check is under this condition in 'if'): - if (protocolHandler.data()) { + if (protocolHandler) { if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2Direct || (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP2 && switchedToHttp2)) { - auto h2Handler = static_cast(protocolHandler.data()); + auto h2Handler = static_cast(protocolHandler.get()); h2Handler->handleConnectionClosure(); } } diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index ecf1e20106..491f5121ac 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -78,6 +78,8 @@ #include +#include + QT_REQUIRE_CONFIG(http); QT_BEGIN_NAMESPACE @@ -120,7 +122,7 @@ public: QAuthenticator proxyAuthenticator; bool authenticationCredentialsSent; bool proxyCredentialsSent; - QScopedPointer protocolHandler; + std::unique_ptr protocolHandler; QMultiMap h2RequestsToSend; bool switchedToHttp2 = false; #ifndef QT_NO_SSL diff --git a/src/network/socket/qsocks5socketengine.cpp b/src/network/socket/qsocks5socketengine.cpp index 3708ce9df2..ed16e2d855 100644 --- a/src/network/socket/qsocks5socketengine.cpp +++ b/src/network/socket/qsocks5socketengine.cpp @@ -56,6 +56,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE static const int MaxWriteBufferSize = 128*1024; @@ -1912,9 +1914,9 @@ QSocks5SocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socke QSOCKS5_DEBUG << "not proxying"; return nullptr; } - QScopedPointer engine(new QSocks5SocketEngine(parent)); + auto engine = std::make_unique(parent); engine->setProxy(proxy); - return engine.take(); + return engine.release(); } QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr socketDescriptor, QObject *parent) diff --git a/src/opengl/qopenglengineshadermanager.cpp b/src/opengl/qopenglengineshadermanager.cpp index eb2aa12d07..cf7424adb1 100644 --- a/src/opengl/qopenglengineshadermanager.cpp +++ b/src/opengl/qopenglengineshadermanager.cpp @@ -46,6 +46,7 @@ #include #include +#include #if defined(QT_DEBUG) #include @@ -372,7 +373,7 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO } } - QScopedPointer newProg; + std::unique_ptr newProg; do { QByteArray fragSource; @@ -395,10 +396,10 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO vertexSource.append(qShaderSnippets[prog.mainVertexShader]); vertexSource.append(qShaderSnippets[prog.positionVertexShader]); #endif - QScopedPointer shaderProgram(new QOpenGLShaderProgram); + auto shaderProgram = std::make_unique(); CachedShader shaderCache(fragSource, vertexSource); - bool inCache = shaderCache.load(shaderProgram.data(), QOpenGLContext::currentContext()); + bool inCache = shaderCache.load(shaderProgram.get(), QOpenGLContext::currentContext()); if (!inCache) { if (!shaderProgram->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexSource)) { @@ -446,7 +447,7 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO } newProg.reset(new QOpenGLEngineShaderProg(prog)); - newProg->program = shaderProgram.take(); + newProg->program = shaderProgram.release(); newProg->program->link(); if (newProg->program->isLinked()) { @@ -478,10 +479,10 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO } } - cachedPrograms.insert(0, newProg.data()); + cachedPrograms.insert(0, newProg.get()); } while (false); - return newProg.take(); + return newProg.release(); } void QOpenGLEngineSharedShaders::cleanupCustomStage(QOpenGLCustomShaderStage* stage) diff --git a/src/opengl/qopenglshaderprogram.cpp b/src/opengl/qopenglshaderprogram.cpp index da3ff392ef..5cb539b5db 100644 --- a/src/opengl/qopenglshaderprogram.cpp +++ b/src/opengl/qopenglshaderprogram.cpp @@ -57,6 +57,7 @@ #endif #include +#include QT_BEGIN_NAMESPACE @@ -3761,12 +3762,12 @@ bool QOpenGLShaderProgramPrivate::compileCacheable() { Q_Q(QOpenGLShaderProgram); for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : qAsConst(binaryProgram.shaders)) { - QScopedPointer s(new QOpenGLShader(qt_shaderStageToType(shader.stage), q)); + auto s = std::make_unique(qt_shaderStageToType(shader.stage), q); if (!s->compileSourceCode(shader.source)) { log = s->log(); return false; } - anonShaders.append(s.take()); + anonShaders.append(s.release()); if (!q->addShader(anonShaders.last())) return false; } diff --git a/src/openglwidgets/qopenglwidget.cpp b/src/openglwidgets/qopenglwidget.cpp index 2ae1a7f215..7c565e10f3 100644 --- a/src/openglwidgets/qopenglwidget.cpp +++ b/src/openglwidgets/qopenglwidget.cpp @@ -748,7 +748,7 @@ void QOpenGLWidgetPrivate::initialize() requestedSamples = requestedFormat.samples(); requestedFormat.setSamples(0); - QScopedPointer ctx(new QOpenGLContext); + auto ctx = std::make_unique(); ctx->setFormat(requestedFormat); if (shareContext) { ctx->setShareContext(shareContext); @@ -793,7 +793,7 @@ void QOpenGLWidgetPrivate::initialize() paintDevice->setSize(q->size() * q->devicePixelRatio()); paintDevice->setDevicePixelRatio(q->devicePixelRatio()); - context = ctx.take(); + context = ctx.release(); initialized = true; q->initializeGL(); diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 397b988e61..fc60e91aa1 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -92,6 +92,8 @@ #include "qwindowsopengltester.h" +#include + static inline void initOpenGlBlacklistResources() { Q_INIT_RESOURCE(openglblacklists); @@ -466,9 +468,9 @@ QPlatformOpenGLContext *QWindowsIntegration::createPlatformOpenGLContext(QOpenGL { qCDebug(lcQpaGl) << __FUNCTION__ << context->format(); if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext()) { - QScopedPointer result(staticOpenGLContext->createContext(context)); + std::unique_ptr result(staticOpenGLContext->createContext(context)); if (result->isValid()) - return result.take(); + return result.release(); } return nullptr; } @@ -498,12 +500,12 @@ QOpenGLContext *QWindowsIntegration::createOpenGLContext(HGLRC ctx, HWND window, return nullptr; if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext()) { - QScopedPointer result(staticOpenGLContext->createContext(ctx, window)); + std::unique_ptr result(staticOpenGLContext->createContext(ctx, window)); if (result->isValid()) { auto *context = new QOpenGLContext; context->setShareContext(shareContext); auto *contextPrivate = QOpenGLContextPrivate::get(context); - contextPrivate->adopt(result.take()); + contextPrivate->adopt(result.release()); return context; } } diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 355249df54..3aeda6f4c0 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -87,6 +87,7 @@ #include #include #include +#include #include #include @@ -1352,9 +1353,9 @@ char *toHexRepresentation(const char *ba, int length) char *toPrettyCString(const char *p, int length) { bool trimmed = false; - QScopedArrayPointer buffer(new char[256]); + auto buffer = std::make_unique(256); const char *end = p + length; - char *dst = buffer.data(); + char *dst = buffer.get(); bool lastWasHexEscape = false; *dst++ = '"'; @@ -1364,7 +1365,7 @@ char *toPrettyCString(const char *p, int length) // 2 bytes: a simple escape sequence (\n) // 3 bytes: "" and a character // 4 bytes: an hex escape sequence (\xHH) - if (dst - buffer.data() > 246) { + if (dst - buffer.get() > 246) { // plus the quote, the three dots and NUL, it's 255 in the worst case trimmed = true; break; @@ -1425,7 +1426,7 @@ char *toPrettyCString(const char *p, int length) *dst++ = '.'; } *dst++ = '\0'; - return buffer.take(); + return buffer.release(); } #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -1451,13 +1452,13 @@ char *toPrettyUnicode(QStringView string) auto length = string.size(); // keep it simple for the vast majority of cases bool trimmed = false; - QScopedArrayPointer buffer(new char[256]); + auto buffer = std::make_unique(256); const auto end = p + length; - char *dst = buffer.data(); + char *dst = buffer.get(); *dst++ = '"'; for ( ; p != end; ++p) { - if (dst - buffer.data() > 245) { + if (dst - buffer.get() > 245) { // plus the quote, the three dots and NUL, it's 250, 251 or 255 trimmed = true; break; @@ -1507,7 +1508,7 @@ char *toPrettyUnicode(QStringView string) *dst++ = '.'; } *dst++ = '\0'; - return buffer.take(); + return buffer.release(); } void TestMethods::invokeTests(QObject *testObject) const diff --git a/src/xml/dom/qdomhelpers.cpp b/src/xml/dom/qdomhelpers.cpp index 48dd0776f3..264a17de3d 100644 --- a/src/xml/dom/qdomhelpers.cpp +++ b/src/xml/dom/qdomhelpers.cpp @@ -45,6 +45,7 @@ #include "qdom_p.h" #include "qxmlstream.h" +#include #include QT_BEGIN_NAMESPACE @@ -129,23 +130,23 @@ bool QDomBuilder::characters(const QString &characters, bool cdata) if (node == doc) return false; - QScopedPointer n; + std::unique_ptr n; if (cdata) { n.reset(doc->createCDATASection(characters)); } else if (!entityName.isEmpty()) { - QScopedPointer e( - new QDomEntityPrivate(doc, nullptr, entityName, QString(), QString(), QString())); + auto e = std::make_unique( + doc, nullptr, entityName, QString(), QString(), QString()); e->value = characters; e->ref.deref(); - doc->doctype()->appendChild(e.data()); - e.take(); + doc->doctype()->appendChild(e.get()); + Q_UNUSED(e.release()); n.reset(doc->createEntityReference(entityName)); } else { n.reset(doc->createTextNode(characters)); } n->setLocation(int(reader->lineNumber()), int(reader->columnNumber())); - node->appendChild(n.data()); - n.take(); + node->appendChild(n.get()); + Q_UNUSED(n.release()); return true; } -- cgit v1.2.3