summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2021-04-12 11:51:23 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-04-13 07:43:48 +0000
commit1d01f7c1bea81a925766e1c0a6cbe2ae7cf2f96c (patch)
tree868f74c87dea7cd54c2898b9a35c0096c97a0548
parentf48d5081eb023cdaf4d819b0276aff7ba877be08 (diff)
QNetworkInformation: Remove the default argument
And the code for loading whatever backend is sorted first. Though, looking at the code it would've never returned 'true' anyway. Change-Id: I7bc2c740e8cb5343e5843cb1d65715d236b92a25 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit b67fe6dc7d27f857a4581e583fe25187c673bcaa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/network/kernel/qnetworkinformation.cpp51
-rw-r--r--src/network/kernel/qnetworkinformation.h2
2 files changed, 23 insertions, 30 deletions
diff --git a/src/network/kernel/qnetworkinformation.cpp b/src/network/kernel/qnetworkinformation.cpp
index 789d75501f..355c6ab411 100644
--- a/src/network/kernel/qnetworkinformation.cpp
+++ b/src/network/kernel/qnetworkinformation.cpp
@@ -171,6 +171,8 @@ QStringList QNetworkInformationPrivate::backendNames()
QNetworkInformation *QNetworkInformationPrivate::create(QStringView name)
{
+ if (name.isEmpty())
+ return nullptr;
if (!dataHolder())
return nullptr;
#ifdef DEBUG_LOADING
@@ -189,40 +191,31 @@ QNetworkInformation *QNetworkInformationPrivate::create(QStringView name)
return dataHolder->instanceHolder.get();
- QNetworkInformationBackend *backend = nullptr;
- if (!name.isEmpty()) {
- const auto nameMatches = [name](QNetworkInformationBackendFactory *factory) {
- return factory->name().compare(name, Qt::CaseInsensitive) == 0;
- };
- auto it = std::find_if(dataHolder->factories.cbegin(), dataHolder->factories.cend(),
- nameMatches);
- if (it == dataHolder->factories.cend()) {
+ const auto nameMatches = [name](QNetworkInformationBackendFactory *factory) {
+ return factory->name().compare(name, Qt::CaseInsensitive) == 0;
+ };
+ auto it = std::find_if(dataHolder->factories.cbegin(), dataHolder->factories.cend(),
+ nameMatches);
+ if (it == dataHolder->factories.cend()) {
#ifdef DEBUG_LOADING
- if (dataHolder->factories.isEmpty()) {
- qDebug("No plugins available");
- } else {
- QString listNames;
- listNames.reserve(8 * dataHolder->factories.count());
- for (const auto *factory : qAsConst(dataHolder->factories))
- listNames += factory->name() + QStringLiteral(", ");
- listNames.chop(2);
- qDebug().nospace() << "Couldn't find " << name << " in list with names: { "
- << listNames << " }";
- }
-#endif
- return nullptr;
+ if (dataHolder->factories.isEmpty()) {
+ qDebug("No plugins available");
+ } else {
+ QString listNames;
+ listNames.reserve(8 * dataHolder->factories.count());
+ for (const auto *factory : qAsConst(dataHolder->factories))
+ listNames += factory->name() + QStringLiteral(", ");
+ listNames.chop(2);
+ qDebug().nospace() << "Couldn't find " << name << " in list with names: { "
+ << listNames << " }";
}
-#ifdef DEBUG_LOADING
- qDebug() << "Creating instance using loader named " << (*it)->name();
#endif
- backend = (*it)->create({});
- } else {
+ return nullptr;
+ }
#ifdef DEBUG_LOADING
- qDebug() << "Creating instance using loader named" << dataHolder->factories.front()->name();
+ qDebug() << "Creating instance using loader named " << (*it)->name();
#endif
- if (!dataHolder->factories.isEmpty())
- backend = dataHolder->factories.front()->create({});
- }
+ QNetworkInformationBackend *backend = (*it)->create({});
if (!backend)
return nullptr;
dataHolder->instanceHolder.reset(new QNetworkInformation(backend));
diff --git a/src/network/kernel/qnetworkinformation.h b/src/network/kernel/qnetworkinformation.h
index 131269caa5..147590d869 100644
--- a/src/network/kernel/qnetworkinformation.h
+++ b/src/network/kernel/qnetworkinformation.h
@@ -77,7 +77,7 @@ public:
virtual bool supports(Features features) const;
- static bool load(QStringView backend = {});
+ static bool load(QStringView backend);
static bool load(Features features);
static QStringList availableBackends();
static QNetworkInformation *instance();