QNI: refactor to avoid tiny lambda slot objects

by just adding the parameter to the signal there's no longer a need for
the tiny lambdas that just call a getter.

Originally the idea was that, since the emission from Backend to the
'frontend' may be a queued emission, I wanted to use the getter so that
the data emitted from the frontend was as up-to-date as possible.
But on one hand, that's not really a big problem, and at the same time
it would then emit the signal twice with the same value.

Change-Id: Ief0959f8cbf06faf1b02a1ed4ae777181ff4f059
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Mårten Nordheim 2021-10-22 09:47:38 +02:00
parent bb220f2d99
commit f670e483c1
2 changed files with 10 additions and 11 deletions

View File

@ -511,12 +511,11 @@ QNetworkInformation::QNetworkInformation(QNetworkInformationBackend *backend)
: QObject(*(new QNetworkInformationPrivate(backend)))
{
connect(backend, &QNetworkInformationBackend::reachabilityChanged, this,
[this]() { emit reachabilityChanged(d_func()->backend->reachability()); });
connect(backend, &QNetworkInformationBackend::behindCaptivePortalChanged, this, [this]() {
emit isBehindCaptivePortalChanged(d_func()->backend->behindCaptivePortal());
});
&QNetworkInformation::reachabilityChanged);
connect(backend, &QNetworkInformationBackend::behindCaptivePortalChanged, this,
&QNetworkInformation::isBehindCaptivePortalChanged);
connect(backend, &QNetworkInformationBackend::transportMediumChanged, this,
[this]() { emit transportMediumChanged(d_func()->backend->transportMedium()); });
&QNetworkInformation::transportMediumChanged);
}
/*!

View File

@ -89,16 +89,16 @@ public:
TransportMedium transportMedium() const { return m_transportMedium; }
Q_SIGNALS:
void reachabilityChanged();
void behindCaptivePortalChanged();
void transportMediumChanged();
void reachabilityChanged(Reachability reachability);
void behindCaptivePortalChanged(bool behindPortal);
void transportMediumChanged(TransportMedium medium);
protected:
void setReachability(QNetworkInformation::Reachability reachability)
{
if (m_reachability != reachability) {
m_reachability = reachability;
emit reachabilityChanged();
emit reachabilityChanged(reachability);
}
}
@ -106,7 +106,7 @@ protected:
{
if (m_behindCaptivePortal != behindPortal) {
m_behindCaptivePortal = behindPortal;
emit behindCaptivePortalChanged();
emit behindCaptivePortalChanged(behindPortal);
}
}
@ -114,7 +114,7 @@ protected:
{
if (m_transportMedium != medium) {
m_transportMedium = medium;
emit transportMediumChanged();
emit transportMediumChanged(medium);
}
}