QLibraryInfo: port from manual memory management to unique_ptr
It's safer and clearer. Also standardize on unique_ptr instead of QScopedPointer, because the latter is not supposed to be movable, so the assignment in QLibrarySettings::load() would not compile. As a drive-by, scope a variable tighter (in an if condition). Task-number: QTBUG-132213 Pick-to: 6.8 Change-Id: Iecdd910af4d06dbd03d2daf3ccf99dd4822f04ac Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit aa1f2064801b39a26a718703817e197a3e31447e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
e23933e868
commit
b79b2edde8
@ -10,7 +10,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "qlibraryinfo.h"
|
#include "qlibraryinfo.h"
|
||||||
#include "qlibraryinfo_p.h"
|
#include "qlibraryinfo_p.h"
|
||||||
#include "qscopedpointer.h"
|
|
||||||
|
|
||||||
#include "qcoreapplication.h"
|
#include "qcoreapplication.h"
|
||||||
|
|
||||||
@ -30,6 +29,8 @@
|
|||||||
# include <qt_windows.h>
|
# include <qt_windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
using namespace Qt::StringLiterals;
|
using namespace Qt::StringLiterals;
|
||||||
@ -38,7 +39,7 @@ extern void qDumpCPUFeatures(); // in qsimd.cpp
|
|||||||
|
|
||||||
#if QT_CONFIG(settings)
|
#if QT_CONFIG(settings)
|
||||||
|
|
||||||
static QSettings *findConfiguration();
|
static std::unique_ptr<QSettings> findConfiguration();
|
||||||
|
|
||||||
struct QLibrarySettings
|
struct QLibrarySettings
|
||||||
{
|
{
|
||||||
@ -47,7 +48,7 @@ struct QLibrarySettings
|
|||||||
bool havePaths();
|
bool havePaths();
|
||||||
QSettings *configuration();
|
QSettings *configuration();
|
||||||
|
|
||||||
QScopedPointer<QSettings> settings;
|
std::unique_ptr<QSettings> settings;
|
||||||
bool paths;
|
bool paths;
|
||||||
bool reloadOnQAppAvailable;
|
bool reloadOnQAppAvailable;
|
||||||
};
|
};
|
||||||
@ -62,7 +63,7 @@ QSettings *QLibrarySettings::configuration()
|
|||||||
{
|
{
|
||||||
if (reloadOnQAppAvailable && QCoreApplication::instance() != nullptr)
|
if (reloadOnQAppAvailable && QCoreApplication::instance() != nullptr)
|
||||||
load();
|
load();
|
||||||
return settings.data();
|
return settings.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QLibrarySettings::havePaths()
|
bool QLibrarySettings::havePaths()
|
||||||
@ -75,8 +76,8 @@ bool QLibrarySettings::havePaths()
|
|||||||
void QLibrarySettings::load()
|
void QLibrarySettings::load()
|
||||||
{
|
{
|
||||||
// If we get any settings here, those won't change when the application shows up.
|
// If we get any settings here, those won't change when the application shows up.
|
||||||
settings.reset(findConfiguration());
|
settings = findConfiguration();
|
||||||
reloadOnQAppAvailable = (settings.data() == nullptr && QCoreApplication::instance() == nullptr);
|
reloadOnQAppAvailable = !settings && !QCoreApplication::instance();
|
||||||
|
|
||||||
if (settings) {
|
if (settings) {
|
||||||
// This code needs to be in the regular library, as otherwise a qt.conf that
|
// This code needs to be in the regular library, as otherwise a qt.conf that
|
||||||
@ -96,14 +97,14 @@ void QLibraryInfoPrivate::setQtconfManualPath(const QString *path)
|
|||||||
qtconfManualPath = path;
|
qtconfManualPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSettings *findConfiguration()
|
static std::unique_ptr<QSettings> findConfiguration()
|
||||||
{
|
{
|
||||||
if (qtconfManualPath)
|
if (qtconfManualPath)
|
||||||
return new QSettings(*qtconfManualPath, QSettings::IniFormat);
|
return std::make_unique<QSettings>(*qtconfManualPath, QSettings::IniFormat);
|
||||||
|
|
||||||
QString qtconfig = QStringLiteral(":/qt/etc/qt.conf");
|
QString qtconfig = QStringLiteral(":/qt/etc/qt.conf");
|
||||||
if (QFile::exists(qtconfig))
|
if (QFile::exists(qtconfig))
|
||||||
return new QSettings(qtconfig, QSettings::IniFormat);
|
return std::make_unique<QSettings>(qtconfig, QSettings::IniFormat);
|
||||||
#ifdef Q_OS_DARWIN
|
#ifdef Q_OS_DARWIN
|
||||||
CFBundleRef bundleRef = CFBundleGetMainBundle();
|
CFBundleRef bundleRef = CFBundleGetMainBundle();
|
||||||
if (bundleRef) {
|
if (bundleRef) {
|
||||||
@ -115,7 +116,7 @@ static QSettings *findConfiguration()
|
|||||||
QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
|
QCFString path = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
|
||||||
qtconfig = QDir::cleanPath(path);
|
qtconfig = QDir::cleanPath(path);
|
||||||
if (QFile::exists(qtconfig))
|
if (QFile::exists(qtconfig))
|
||||||
return new QSettings(qtconfig, QSettings::IniFormat);
|
return std::make_unique<QSettings>(qtconfig, QSettings::IniFormat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -123,10 +124,10 @@ static QSettings *findConfiguration()
|
|||||||
QDir pwd(QCoreApplication::applicationDirPath());
|
QDir pwd(QCoreApplication::applicationDirPath());
|
||||||
qtconfig = pwd.filePath(u"qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf"_s);
|
qtconfig = pwd.filePath(u"qt" QT_STRINGIFY(QT_VERSION_MAJOR) ".conf"_s);
|
||||||
if (QFile::exists(qtconfig))
|
if (QFile::exists(qtconfig))
|
||||||
return new QSettings(qtconfig, QSettings::IniFormat);
|
return std::make_unique<QSettings>(qtconfig, QSettings::IniFormat);
|
||||||
qtconfig = pwd.filePath("qt.conf"_L1);
|
qtconfig = pwd.filePath("qt.conf"_L1);
|
||||||
if (QFile::exists(qtconfig))
|
if (QFile::exists(qtconfig))
|
||||||
return new QSettings(qtconfig, QSettings::IniFormat);
|
return std::make_unique<QSettings>(qtconfig, QSettings::IniFormat);
|
||||||
}
|
}
|
||||||
return nullptr; //no luck
|
return nullptr; //no luck
|
||||||
}
|
}
|
||||||
@ -688,8 +689,7 @@ QString QLibraryInfoPrivate::path(QLibraryInfo::LibraryPath p, UsageMode usageMo
|
|||||||
QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
|
QStringList QLibraryInfo::platformPluginArguments(const QString &platformName)
|
||||||
{
|
{
|
||||||
#if QT_CONFIG(settings)
|
#if QT_CONFIG(settings)
|
||||||
QScopedPointer<const QSettings> settings(findConfiguration());
|
if (const auto settings = findConfiguration()) {
|
||||||
if (!settings.isNull()) {
|
|
||||||
const QString key = "Platforms/"_L1
|
const QString key = "Platforms/"_L1
|
||||||
+ platformName
|
+ platformName
|
||||||
+ "Arguments"_L1;
|
+ "Arguments"_L1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user