summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2024-07-05 14:41:02 +0200
committerMate Barany <mate.barany@qt.io>2024-07-29 14:29:46 +0200
commit36aa5fc3fa361ecb6f7bb035c3cace3dd14735e0 (patch)
tree99be8903cec4ea76ce352fe83fd137985e5f7972 /src
parent0c0f57dd1ea27239255e77820e10f598d0f72551 (diff)
Initialize all data members in QNetworkAccessCache::CacheableObject
Address the "A constructor must initialize all data members of the class" warning. The class should accept initial values as argument of a (possibly protected) constructor if it expects them to be set by a derived class. Add an enum Option and a protected constructor that can be called by the derived classes with the enum values. This makes setExpires and setShareable redundant so remove them. Found by an Axivion scan. Pick-to: 6.8 6.7 6.5 Task-number: QTBUG-125026 Change-Id: Ia8a2a19469a2c0185b5d2e6b2a0895e897f33f28 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpthreaddelegate.cpp4
-rw-r--r--src/network/access/qnetworkaccessauthenticationmanager.cpp3
-rw-r--r--src/network/access/qnetworkaccesscache.cpp17
-rw-r--r--src/network/access/qnetworkaccesscache_p.h15
4 files changed, 17 insertions, 22 deletions
diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp
index 1e11c9cd96a..bd44e570378 100644
--- a/src/network/access/qhttpthreaddelegate.cpp
+++ b/src/network/access/qhttpthreaddelegate.cpp
@@ -151,9 +151,9 @@ public:
QNetworkAccessCachedHttpConnection(quint16 connectionCount, const QString &hostName, quint16 port, bool encrypt, bool isLocalSocket,
QHttpNetworkConnection::ConnectionType connectionType)
: QHttpNetworkConnection(connectionCount, hostName, port, encrypt, isLocalSocket, /*parent=*/nullptr, connectionType)
+ ,CacheableObject(Option::Expires | Option::Shareable)
{
- setExpires(true);
- setShareable(true);
+
}
virtual void dispose() override
diff --git a/src/network/access/qnetworkaccessauthenticationmanager.cpp b/src/network/access/qnetworkaccessauthenticationmanager.cpp
index ab7c27b885e..6e86d6387c2 100644
--- a/src/network/access/qnetworkaccessauthenticationmanager.cpp
+++ b/src/network/access/qnetworkaccessauthenticationmanager.cpp
@@ -22,9 +22,8 @@ class QNetworkAuthenticationCache : private QList<QNetworkAuthenticationCredenti
{
public:
QNetworkAuthenticationCache()
+ : CacheableObject(Option::Shareable)
{
- setExpires(false);
- setShareable(true);
reserve(1);
}
diff --git a/src/network/access/qnetworkaccesscache.cpp b/src/network/access/qnetworkaccesscache.cpp
index b92bd69826c..e4f3aab1b19 100644
--- a/src/network/access/qnetworkaccesscache.cpp
+++ b/src/network/access/qnetworkaccesscache.cpp
@@ -31,10 +31,11 @@ struct QNetworkAccessCache::Node
int useCount = 0;
};
-QNetworkAccessCache::CacheableObject::CacheableObject()
+QNetworkAccessCache::CacheableObject::CacheableObject(Options options)
+ : expires(options & Option::Expires),
+ shareable(options & Option::Shareable)
{
- // leave the members uninitialized
- // they must be initialized by the derived class's constructor
+
}
QNetworkAccessCache::CacheableObject::~CacheableObject()
@@ -46,16 +47,6 @@ QNetworkAccessCache::CacheableObject::~CacheableObject()
#endif
}
-void QNetworkAccessCache::CacheableObject::setExpires(bool enable)
-{
- expires = enable;
-}
-
-void QNetworkAccessCache::CacheableObject::setShareable(bool enable)
-{
- shareable = enable;
-}
-
QNetworkAccessCache::~QNetworkAccessCache()
{
clear();
diff --git a/src/network/access/qnetworkaccesscache_p.h b/src/network/access/qnetworkaccesscache_p.h
index 3ea0ac986f6..b672f41142d 100644
--- a/src/network/access/qnetworkaccesscache_p.h
+++ b/src/network/access/qnetworkaccesscache_p.h
@@ -19,6 +19,7 @@
#include "QtCore/qobject.h"
#include "QtCore/qbasictimer.h"
#include "QtCore/qbytearray.h"
+#include <QtCore/qflags.h>
#include "QtCore/qhash.h"
#include "QtCore/qmetatype.h"
@@ -36,7 +37,6 @@ class QNetworkAccessCache: public QObject
public:
struct Node;
typedef QHash<QByteArray, Node *> NodeHash;
-
class CacheableObject
{
friend class QNetworkAccessCache;
@@ -45,14 +45,17 @@ public:
bool shareable;
qint64 expiryTimeoutSeconds = -1;
public:
- CacheableObject();
+ enum class Option {
+ Expires = 0x01,
+ Shareable = 0x02,
+ };
+ typedef QFlags<Option> Options; // #### QTBUG-127269
+
virtual ~CacheableObject();
virtual void dispose() = 0;
inline QByteArray cacheKey() const { return key; }
-
protected:
- void setExpires(bool enable);
- void setShareable(bool enable);
+ explicit CacheableObject(Options options);
};
~QNetworkAccessCache();
@@ -85,6 +88,8 @@ private:
bool emitEntryReady(Node *node, QObject *target, const char *member);
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkAccessCache::CacheableObject::Options)
+
QT_END_NAMESPACE
#endif