QtNetwork: use nullary version of qRegisterMetaType<T>("T")

Using the nullary version has the advantage that multiple calls
during a program run are much more efficient, since an inlined
atomic is used to store the result. It also ensures that
Q_DECLARE_METATYPE(T) has been used, whereas qRegisterMetaType<T>("T")
will happily register anything. So I've added the macro where it
was missing, or moved it to a central place when it existed
hidden.

In tst_qnetworkreply, this became a bit tricky, because a private
header is conditionally included, so moved the Q_DECLARE_METATYPE()
into a conditional section, too.

Change-Id: I71484523e4277f4697b7d4b2ddc3505375162727
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
Marc Mutz 2012-07-20 10:56:54 +02:00 committed by Qt by Nokia
parent 7d110111da
commit 79b742b7e0
29 changed files with 42 additions and 53 deletions

View File

@ -125,7 +125,7 @@ void QHttpNetworkConnectionChannel::init()
// will then emit a signal to the user of QNetworkReply
// but cannot be caught because the user did not have a chance yet
// to connect to QNetworkReply's signals.
qRegisterMetaType<QAbstractSocket::SocketError>("QAbstractSocket::SocketError");
qRegisterMetaType<QAbstractSocket::SocketError>();
QObject::connect(socket, SIGNAL(disconnected()),
this, SLOT(_q_disconnected()),
Qt::QueuedConnection);

View File

@ -155,6 +155,8 @@ public:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QHttpNetworkRequest)
#endif // QT_NO_HTTP

View File

@ -407,20 +407,20 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent)
{
ensureInitialized();
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
qRegisterMetaType<QNetworkReply::NetworkError>();
#ifndef QT_NO_NETWORKPROXY
qRegisterMetaType<QNetworkProxy>("QNetworkProxy");
qRegisterMetaType<QNetworkProxy>();
#endif
#ifndef QT_NO_SSL
qRegisterMetaType<QList<QSslError> >("QList<QSslError>");
qRegisterMetaType<QSslConfiguration>("QSslConfiguration");
qRegisterMetaType<QList<QSslError> >();
qRegisterMetaType<QSslConfiguration>();
#endif
qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >("QList<QPair<QByteArray,QByteArray> >");
qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >();
#ifndef QT_NO_HTTP
qRegisterMetaType<QHttpNetworkRequest>("QHttpNetworkRequest");
qRegisterMetaType<QHttpNetworkRequest>();
#endif
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
qRegisterMetaType<QSharedPointer<char> >("QSharedPointer<char>");
qRegisterMetaType<QNetworkReply::NetworkError>();
qRegisterMetaType<QSharedPointer<char> >();
}
/*!

View File

@ -180,6 +180,8 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QNetworkReply::NetworkError)
QT_END_HEADER
#endif

View File

@ -63,8 +63,6 @@
#include <string.h> // for strchr
Q_DECLARE_METATYPE(QSharedPointer<char>)
QT_BEGIN_NAMESPACE
class QNetworkProxy;

View File

@ -52,8 +52,6 @@
#include <QtCore/QCoreApplication>
Q_DECLARE_METATYPE(QSharedPointer<char>)
QT_BEGIN_NAMESPACE
inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
@ -1134,7 +1132,7 @@ QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent,
setUrl(req.url());
setOperation(op);
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError");
qRegisterMetaType<QNetworkReply::NetworkError>();
QString msg = QCoreApplication::translate("QNetworkAccessManager",
"Network access is disabled.");

View File

@ -239,4 +239,6 @@ protected:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QSharedPointer<char>)
#endif

View File

@ -62,8 +62,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
QNetworkConfigurationManagerPrivate::QNetworkConfigurationManagerPrivate()
: QObject(), pollTimer(0), mutex(QMutex::Recursive), forcedPolling(0), firstUpdate(true)
{
qRegisterMetaType<QNetworkConfiguration>("QNetworkConfiguration");
qRegisterMetaType<QNetworkConfigurationPrivatePointer>("QNetworkConfigurationPrivatePointer");
qRegisterMetaType<QNetworkConfiguration>();
qRegisterMetaType<QNetworkConfigurationPrivatePointer>();
}
void QNetworkConfigurationManagerPrivate::initialize()

View File

@ -47,6 +47,7 @@
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
#include <QtCore/qmetatype.h>
QT_BEGIN_HEADER
@ -125,6 +126,8 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QNetworkConfiguration)
QT_END_HEADER
#endif // QNETWORKCONFIGURATION_H

View File

@ -99,4 +99,6 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QNetworkConfigurationPrivatePointer)
#endif // QNETWORKCONFIGURATIONPRIVATE_H

View File

@ -159,7 +159,7 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
return -1;
}
qRegisterMetaType<QHostInfo>("QHostInfo");
qRegisterMetaType<QHostInfo>();
int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID

View File

@ -96,6 +96,8 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QHostInfo)
QT_END_HEADER
#endif // QHOSTINFO_H

View File

@ -215,6 +215,8 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QNetworkProxy)
QT_END_HEADER
#endif // QT_NO_NETWORKPROXY

View File

@ -238,6 +238,9 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug, QAbstractSocket::SocketState);
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
QT_END_HEADER
#endif // QABSTRACTSOCKET_H

View File

@ -158,6 +158,8 @@ Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, QSslCertificate::SubjectInfo in
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QSslCertificate)
QT_END_HEADER
#endif

View File

@ -138,6 +138,8 @@ private:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QSslConfiguration)
QT_END_HEADER
#endif

View File

@ -60,10 +60,6 @@
#include <QtCore/qvarlengtharray.h>
#include <QLibrary> // for loading the security lib for the CA store
#ifdef Q_OS_WIN
Q_DECLARE_METATYPE(QSslCertificate);
#endif
QT_BEGIN_NAMESPACE
#if defined(Q_OS_MAC) && !defined(Q_OS_IOS)

View File

@ -80,6 +80,8 @@ Q_SIGNALS:
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QBearerEngineImpl::ConnectionError)
#endif // QT_NO_BEARERMANAGEMENT
#endif // QBEARERENGINE_IMPL_H

View File

@ -96,14 +96,14 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface()
state = QNetworkSession::Invalid;
lastError = QNetworkSession::UnknownSessionError;
qRegisterMetaType<QBearerEngineImpl::ConnectionError>("QBearerEngineImpl::ConnectionError");
qRegisterMetaType<QBearerEngineImpl::ConnectionError>();
switch (publicConfig.type()) {
case QNetworkConfiguration::InternetAccessPoint:
activeConfig = publicConfig;
engine = getEngineFromId(activeConfig.identifier());
if (engine) {
qRegisterMetaType<QNetworkConfigurationPrivatePointer>("QNetworkConfigurationPrivatePointer");
qRegisterMetaType<QNetworkConfigurationPrivatePointer>();
connect(engine, SIGNAL(configurationChanged(QNetworkConfigurationPrivatePointer)),
this, SLOT(configurationChanged(QNetworkConfigurationPrivatePointer)),
Qt::QueuedConnection);

View File

@ -57,10 +57,6 @@
#include "../../../network-settings.h"
#ifndef QT_NO_BEARERMANAGEMENT
Q_DECLARE_METATYPE(QNetworkConfiguration)
#endif
class tst_QFtp : public QObject
{
Q_OBJECT

View File

@ -746,7 +746,6 @@ void tst_QHttpNetworkConnection::ignoresslerror()
#endif
#ifdef QT_NO_SSL
Q_DECLARE_METATYPE(QNetworkReply::NetworkError)
void tst_QHttpNetworkConnection::nossl_data()
{
QTest::addColumn<QString>("protocol");

View File

@ -78,7 +78,10 @@
#include <QtNetwork/private/qnetworksession_p.h>
#endif
#ifdef QT_BUILD_INTERNAL
#include <QtNetwork/private/qnetworkreplyimpl_p.h> // implicitly included by qnetworkaccessmanager_p.h currently, but don't rely on that being true forever
#include <QtNetwork/private/qnetworkaccessmanager_p.h>
#else
Q_DECLARE_METATYPE(QSharedPointer<char>)
#endif
#ifdef Q_OS_UNIX
@ -89,19 +92,12 @@
#include "../../../network-settings.h"
Q_DECLARE_METATYPE(QSharedPointer<char>)
Q_DECLARE_METATYPE(QNetworkReply*)
Q_DECLARE_METATYPE(QAuthenticator*)
Q_DECLARE_METATYPE(QNetworkProxy)
Q_DECLARE_METATYPE(QNetworkProxyQuery)
Q_DECLARE_METATYPE(QList<QNetworkProxy>)
Q_DECLARE_METATYPE(QNetworkReply::NetworkError)
Q_DECLARE_METATYPE(QBuffer*)
Q_DECLARE_METATYPE(QHttpMultiPart *)
Q_DECLARE_METATYPE(QList<QFile*>) // for multiparts
#ifndef QT_NO_SSL
Q_DECLARE_METATYPE(QSslConfiguration)
#endif
typedef QSharedPointer<QNetworkReply> QNetworkReplyPtr;

View File

@ -57,7 +57,6 @@ QT_USE_NAMESPACE
//#define QNETWORKSESSION_MANUAL_TESTS 1
#ifndef QT_NO_BEARERMANAGEMENT
Q_DECLARE_METATYPE(QNetworkConfiguration)
Q_DECLARE_METATYPE(QNetworkConfiguration::Type)
#endif

View File

@ -55,9 +55,6 @@
#include <QNetworkRequest>
#include <QList>
Q_DECLARE_METATYPE(QNetworkConfiguration);
Q_DECLARE_METATYPE(QList<QNetworkProxy>);
#include <QThread>
class tst_QNetworkProxyFactory : public QObject {

View File

@ -68,8 +68,6 @@
#include <qhostinfo.h>
#include <QNetworkProxy>
Q_DECLARE_METATYPE(QNetworkProxy)
Q_DECLARE_METATYPE(QList<QNetworkProxy>)
#include <QNetworkSession>
#include <QNetworkConfiguration>

View File

@ -92,11 +92,6 @@
#include "../../../network-settings.h"
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
Q_DECLARE_METATYPE(QNetworkProxy)
Q_DECLARE_METATYPE(QList<QNetworkProxy>)
QT_FORWARD_DECLARE_CLASS(QTcpSocket)
class SocketPair;

View File

@ -63,15 +63,12 @@
#include "../../../network-settings.h"
Q_DECLARE_METATYPE(QAbstractSocket::SocketState)
Q_DECLARE_METATYPE(QAbstractSocket::SocketError)
#ifndef QT_NO_SSL
Q_DECLARE_METATYPE(QSslSocket::SslMode)
typedef QList<QSslError::SslError> SslErrorList;
Q_DECLARE_METATYPE(SslErrorList)
Q_DECLARE_METATYPE(QSslError)
Q_DECLARE_METATYPE(QSsl::SslProtocol)
Q_DECLARE_METATYPE(QSslConfiguration)
#endif
#if defined Q_OS_HPUX && defined Q_CC_GNU

View File

@ -51,8 +51,6 @@
#include <qhostinfo.h>
#include <QNetworkProxy>
Q_DECLARE_METATYPE(QNetworkProxy)
Q_DECLARE_METATYPE(QList<QNetworkProxy>)
#include "../../../../auto/network-settings.h"

View File

@ -45,8 +45,6 @@
#include <QtNetwork>
#include <QtWidgets>
Q_DECLARE_METATYPE(QNetworkConfiguration)
BearerEx::BearerEx(QWidget* parent)
: QMainWindow(parent)
{