diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2022-03-04 12:28:49 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2022-03-08 15:44:17 +0100 |
commit | 034d8898f8166423db085da529787e56204c8e15 (patch) | |
tree | f58e930c7880d1cd79cd39745ed366d27dcd9e55 /src/corelib | |
parent | 87725ee75981ec9ab25456c41acc74681c85ae2e (diff) |
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>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 23 | ||||
-rw-r--r-- | src/corelib/kernel/qmetaobject.cpp | 5 | ||||
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 5 | ||||
-rw-r--r-- | src/corelib/thread/qthreadpool.cpp | 9 |
4 files changed, 23 insertions, 19 deletions
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 <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; diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index f2aafba008..0c9f54c791 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -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) { diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 8f528177d9..13708be391 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -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]; 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 <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); } /*! |