Fix deprecated uses of QScopedPointer

By changing it to unique_ptr.

Pick-to: 6.2 6.3
Change-Id: I91abb69445b537d4c95983ae735341882352b29d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2022-03-04 12:28:49 +01:00
parent 87725ee759
commit 034d8898f8
26 changed files with 144 additions and 109 deletions

View File

@ -134,6 +134,7 @@
#endif
#include <algorithm>
#include <memory>
QT_BEGIN_NAMESPACE
@ -391,8 +392,8 @@ struct QCoreApplicationData {
bool applicationVersionSet; // true if setApplicationVersion was called
#if QT_CONFIG(library)
QScopedPointer<QStringList> app_libpaths;
QScopedPointer<QStringList> manual_libpaths;
std::unique_ptr<QStringList> app_libpaths;
std::unique_ptr<QStringList> 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<QEvent> eventDeleter(event);
std::unique_ptr<QEvent> 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;

View File

@ -62,6 +62,7 @@
#include "private/qmetaobject_moc_p.h"
#include <ctype.h>
#include <memory>
QT_BEGIN_NAMESPACE
@ -2399,7 +2400,7 @@ bool QMetaMethod::invoke(QObject *object,
return false;
}
QScopedPointer<QMetaCallEvent> event(new QMetaCallEvent(idx_offset, idx_relative, callFunction, nullptr, -1, paramCount));
auto event = std::make_unique<QMetaCallEvent>(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) {

View File

@ -71,6 +71,7 @@
#include <new>
#include <mutex>
#include <memory>
#include <ctype.h>
#include <limits.h>
@ -125,7 +126,7 @@ static int *queuedConnectionTypes(const QMetaMethod &method)
static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc)
{
QScopedArrayPointer<int> types(new int[argc + 1]);
auto types = std::make_unique<int[]>(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];

View File

@ -43,6 +43,7 @@
#include "qcoreapplication.h"
#include <algorithm>
#include <memory>
QT_BEGIN_NAMESPACE
@ -274,16 +275,16 @@ bool QThreadPoolPrivate::tooManyThreadsActive() const
void QThreadPoolPrivate::startThread(QRunnable *runnable)
{
Q_ASSERT(runnable != nullptr);
QScopedPointer<QThreadPoolThread> thread(new QThreadPoolThread(this));
auto thread = std::make_unique<QThreadPoolThread>(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);
}
/*!

View File

@ -46,6 +46,8 @@
#include <qpainter.h>
#include <private/qguiapplication_p.h>
#include <memory>
QT_BEGIN_NAMESPACE
/*!
@ -189,10 +191,10 @@ static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags)
image.setColor(1, c0);
}
QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType));
std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType));
data->fromImageInPlace(image, flags | Qt::MonoOnly);
return QBitmap::fromPixmap(QPixmap(data.take()));
return QBitmap::fromPixmap(QPixmap(data.release()));
}
/*!

View File

@ -77,6 +77,8 @@
#include <qtgui_tracepoints_p.h>
#include <memory>
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<QImageData> d(new QImageData);
auto d = std::make_unique<QImageData>();
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()

View File

@ -68,6 +68,8 @@
#include <qtgui_tracepoints_p.h>
#include <memory>
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<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
std::unique_ptr<QPlatformPixmap> 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<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
std::unique_ptr<QPlatformPixmap> 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<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
data->fromImageReader(imageReader, flags);
return QPixmap(data.take());
return QPixmap(data.release());
}
/*!

View File

@ -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<QFileSystemModelPrivate::QFileSystemNode> nodeToRename(parentNode->children.take(oldName));
std::unique_ptr<QFileSystemModelPrivate::QFileSystemNode> 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();

View File

@ -52,6 +52,7 @@
#include <private/qpaintengineex_p.h>
#include <private/qtextengine_p.h>
#include <memory>
QT_BEGIN_NAMESPACE
@ -1009,9 +1010,9 @@ QPixmap QPaintEngine::createPixmap(QSize size)
return QPixmap();
}
QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
std::unique_ptr<QPlatformPixmap> 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<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::PixmapType));
std::unique_ptr<QPlatformPixmap> 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()

View File

@ -38,6 +38,7 @@
****************************************************************************/
// QtCore
#include <memory>
#include <qdebug.h>
#include <qmath.h>
#include <qmutex.h>
@ -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<QPainterPrivate>) == sizeof(std::unique_ptr<QPainterPrivate>));
#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) {

View File

@ -48,6 +48,7 @@
#include <QtGui/qpixmap.h>
#include <QtGui/qimage.h>
#include <QtGui/qtextoption.h>
#include <memory>
#ifndef QT_INCLUDE_COMPAT
#include <QtGui/qpolygon.h>
@ -448,7 +449,7 @@ public:
private:
Q_DISABLE_COPY(QPainter)
QScopedPointer<QPainterPrivate> d_ptr;
std::unique_ptr<QPainterPrivate> d_ptr;
friend class QWidget;
friend class QFontEngine;

View File

@ -252,7 +252,7 @@ public:
static QPainterPrivate *get(QPainter *painter)
{
return painter->d_ptr.data();
return painter->d_ptr.get();
}
QTransform viewTransform() const;

View File

@ -48,6 +48,7 @@
#include "qbitmap.h"
#include "qtransform.h"
#include <memory>
#include <private/qdebug_p.h>
#ifdef Q_OS_WIN
@ -3915,7 +3916,7 @@ QRegion &QRegion::operator=(const QRegion &r)
QRegion QRegion::copy() const
{
QRegion r;
QScopedPointer<QRegionData> x(new QRegionData);
auto x = std::make_unique<QRegionData>();
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;
}

View File

@ -55,6 +55,8 @@
#include "qrhimetal_p_p.h"
#endif
#include <memory>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(QRHI_LOG_INFO, "qt.rhi.general")
@ -5305,7 +5307,7 @@ QRhi::~QRhi()
*/
QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRhiNativeHandles *importDevice)
{
QScopedPointer<QRhi> r(new QRhi);
std::unique_ptr<QRhi> r(new QRhi);
switch (impl) {
case Null:
@ -5351,7 +5353,7 @@ QRhi *QRhi::create(Implementation impl, QRhiInitParams *params, Flags flags, QRh
}
if (r->d) {
r->d->q = r.data();
r->d->q = r.get();
// Play nice with QSG_INFO since that is still the most commonly used
// way to get graphics info printed from Qt Quick apps, and the Quick
@ -5364,7 +5366,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();
}
}

View File

@ -59,6 +59,8 @@
#include <qmath.h>
#include <qendian.h>
#include <memory>
#include <ft2build.h>
#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<QFreetypeFace> newFreetype(new QFreetypeFace);
const auto deleter = [](QFreetypeFace *f) { delete f; };
std::unique_ptr<QFreetypeFace, decltype(deleter)> 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<QFontEngineFT> engine(new QFontEngineFT(fontDef));
auto engine = std::make_unique<QFontEngineFT>(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<QFont::HintingPreference>(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<uchar> glyph_buffer;
std::unique_ptr<uchar[]> 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);

View File

@ -117,7 +117,6 @@ public:
private:
friend class QFontEngineFT;
friend class QtFreetypeData;
friend struct QScopedPointerDeleter<QFreetypeFace>;
QFreetypeFace() = default;
~QFreetypeFace() {}
void cleanup();

View File

@ -48,6 +48,8 @@
#include <qdebug.h>
#include <qdir.h>
#include <memory>
#include <zlib.h>
// 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<QFile> f(new QFile(archive));
auto f = std::make_unique<QFile>(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<QFile> f(new QFile(fileName));
auto f = std::make_unique<QFile>(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;
}

View File

@ -58,6 +58,8 @@
#include "private/qnetconmonitor_p.h"
#include <memory>
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<ProtocolHandlerDeleter> deleter(new ProtocolHandlerDeleter(oldHandler));
QAbstractProtocolHandler *oldHandler = protocolHandler.get();
auto deleter = std::make_unique<ProtocolHandlerDeleter>(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<QHttp2ProtocolHandler *>(protocolHandler.data());
QHttp2ProtocolHandler *h2c = static_cast<QHttp2ProtocolHandler *>(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<QHttp2ProtocolHandler *>(protocolHandler.data());
auto h2Handler = static_cast<QHttp2ProtocolHandler *>(protocolHandler.get());
h2Handler->handleConnectionClosure();
}
}

View File

@ -78,6 +78,8 @@
#include <QtCore/qscopedpointer.h>
#include <memory>
QT_REQUIRE_CONFIG(http);
QT_BEGIN_NAMESPACE
@ -120,7 +122,7 @@ public:
QAuthenticator proxyAuthenticator;
bool authenticationCredentialsSent;
bool proxyCredentialsSent;
QScopedPointer<QAbstractProtocolHandler> protocolHandler;
std::unique_ptr<QAbstractProtocolHandler> protocolHandler;
QMultiMap<int, HttpMessagePair> h2RequestsToSend;
bool switchedToHttp2 = false;
#ifndef QT_NO_SSL

View File

@ -56,6 +56,8 @@
#include <qendian.h>
#include <qnetworkinterface.h>
#include <memory>
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<QSocks5SocketEngine> engine(new QSocks5SocketEngine(parent));
auto engine = std::make_unique<QSocks5SocketEngine>(parent);
engine->setProxy(proxy);
return engine.take();
return engine.release();
}
QAbstractSocketEngine *QSocks5SocketEngineHandler::createSocketEngine(qintptr socketDescriptor, QObject *parent)

View File

@ -46,6 +46,7 @@
#include <QtCore/qthreadstorage.h>
#include <algorithm>
#include <memory>
#if defined(QT_DEBUG)
#include <QMetaEnum>
@ -372,7 +373,7 @@ QOpenGLEngineShaderProg *QOpenGLEngineSharedShaders::findProgramInCache(const QO
}
}
QScopedPointer<QOpenGLEngineShaderProg> newProg;
std::unique_ptr<QOpenGLEngineShaderProg> 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<QOpenGLShaderProgram> shaderProgram(new QOpenGLShaderProgram);
auto shaderProgram = std::make_unique<QOpenGLShaderProgram>();
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)

View File

@ -57,6 +57,7 @@
#endif
#include <algorithm>
#include <memory>
QT_BEGIN_NAMESPACE
@ -3761,12 +3762,12 @@ bool QOpenGLShaderProgramPrivate::compileCacheable()
{
Q_Q(QOpenGLShaderProgram);
for (const QOpenGLProgramBinaryCache::ShaderDesc &shader : qAsConst(binaryProgram.shaders)) {
QScopedPointer<QOpenGLShader> s(new QOpenGLShader(qt_shaderStageToType(shader.stage), q));
auto s = std::make_unique<QOpenGLShader>(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;
}

View File

@ -748,7 +748,7 @@ void QOpenGLWidgetPrivate::initialize()
requestedSamples = requestedFormat.samples();
requestedFormat.setSamples(0);
QScopedPointer<QOpenGLContext> ctx(new QOpenGLContext);
auto ctx = std::make_unique<QOpenGLContext>();
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();

View File

@ -92,6 +92,8 @@
#include "qwindowsopengltester.h"
#include <memory>
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<QWindowsOpenGLContext> result(staticOpenGLContext->createContext(context));
std::unique_ptr<QWindowsOpenGLContext> 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<QWindowsOpenGLContext> result(staticOpenGLContext->createContext(ctx, window));
std::unique_ptr<QWindowsOpenGLContext> 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;
}
}

View File

@ -87,6 +87,7 @@
#include <algorithm>
#include <mutex>
#include <chrono>
#include <memory>
#include <stdarg.h>
#include <stdio.h>
@ -1357,9 +1358,9 @@ char *toHexRepresentation(const char *ba, int length)
char *toPrettyCString(const char *p, int length)
{
bool trimmed = false;
QScopedArrayPointer<char> buffer(new char[256]);
auto buffer = std::make_unique<char[]>(256);
const char *end = p + length;
char *dst = buffer.data();
char *dst = buffer.get();
bool lastWasHexEscape = false;
*dst++ = '"';
@ -1369,7 +1370,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;
@ -1430,7 +1431,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)
@ -1456,13 +1457,13 @@ char *toPrettyUnicode(QStringView string)
auto length = string.size();
// keep it simple for the vast majority of cases
bool trimmed = false;
QScopedArrayPointer<char> buffer(new char[256]);
auto buffer = std::make_unique<char[]>(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;
@ -1512,7 +1513,7 @@ char *toPrettyUnicode(QStringView string)
*dst++ = '.';
}
*dst++ = '\0';
return buffer.take();
return buffer.release();
}
void TestMethods::invokeTests(QObject *testObject) const

View File

@ -45,6 +45,7 @@
#include "qdom_p.h"
#include "qxmlstream.h"
#include <memory>
#include <stack>
QT_BEGIN_NAMESPACE
@ -129,23 +130,23 @@ bool QDomBuilder::characters(const QString &characters, bool cdata)
if (node == doc)
return false;
QScopedPointer<QDomNodePrivate> n;
std::unique_ptr<QDomNodePrivate> n;
if (cdata) {
n.reset(doc->createCDATASection(characters));
} else if (!entityName.isEmpty()) {
QScopedPointer<QDomEntityPrivate> e(
new QDomEntityPrivate(doc, nullptr, entityName, QString(), QString(), QString()));
auto e = std::make_unique<QDomEntityPrivate>(
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;
}