QtDBus: use qMetaTypeId<T>() instead of qRegisterMetaType<T>("T")
Using qMetaTypeId<T> 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> (the unary version) will happily register anything. Had to add a proper default constructor to QDBusError, as the one doubling as the default constructor wasn't available under QT_BOOTSTRAP, but Q_DECLARE_METATYPE requires a default ctor. Also changed a nullary qRegisterMetaType() to qMetaTypeId() in qDBusRegisterMetaType(). They're equivalent, since the former just calls the latter, but apart from the miniscule optimisation that the compiler has to instantiate one function less, the result is also used, so using qMetaTypeId() better expresses what 'id' is. Change-Id: Ib9dde17923ab9ee55f9464138a625ab8cd55c482 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
95232af3ef
commit
e9ecf1b420
@ -250,6 +250,16 @@ static inline QDBusError::ErrorType get(const char *name)
|
||||
\value InvalidInterface The interface is invalid.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Constructs a QDBusError that represents no error.
|
||||
*/
|
||||
QDBusError::QDBusError()
|
||||
: code(NoError)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
/*!
|
||||
\internal
|
||||
|
@ -95,8 +95,9 @@ public:
|
||||
#endif
|
||||
};
|
||||
|
||||
QDBusError();
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
explicit QDBusError(const DBusError *error = 0);
|
||||
explicit QDBusError(const DBusError *error);
|
||||
/*implicit*/ QDBusError(const QDBusMessage& msg);
|
||||
#endif
|
||||
QDBusError(ErrorType error, const QString &message);
|
||||
@ -126,6 +127,8 @@ Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusError &);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(QDBusError)
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif // QT_NO_DBUS
|
||||
|
@ -124,6 +124,8 @@ Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusMessage &);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
Q_DECLARE_METATYPE(QDBusMessage)
|
||||
|
||||
QT_END_HEADER
|
||||
|
||||
#endif // QT_NO_DBUS
|
||||
|
@ -105,15 +105,15 @@ void QDBusMetaTypeId::init()
|
||||
// set the guard variable at the end
|
||||
if (!initialized) {
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
// register our types with QtCore
|
||||
message = qRegisterMetaType<QDBusMessage>("QDBusMessage");
|
||||
error = qRegisterMetaType<QDBusError>("QDBusError");
|
||||
// register our types with QtCore (calling qMetaTypeId<T>() does this implicitly)
|
||||
message = qMetaTypeId<QDBusMessage>();
|
||||
error = qMetaTypeId<QDBusError>();
|
||||
#endif
|
||||
argument = qRegisterMetaType<QDBusArgument>("QDBusArgument");
|
||||
variant = qRegisterMetaType<QDBusVariant>("QDBusVariant");
|
||||
objectpath = qRegisterMetaType<QDBusObjectPath>("QDBusObjectPath");
|
||||
signature = qRegisterMetaType<QDBusSignature>("QDBusSignature");
|
||||
unixfd = qRegisterMetaType<QDBusUnixFileDescriptor>("QDBusUnixFileDescriptor");
|
||||
argument = qMetaTypeId<QDBusArgument>();
|
||||
variant = qMetaTypeId<QDBusVariant>();
|
||||
objectpath = qMetaTypeId<QDBusObjectPath>();
|
||||
signature = qMetaTypeId<QDBusSignature>();
|
||||
unixfd = qMetaTypeId<QDBusUnixFileDescriptor>();
|
||||
|
||||
#ifndef QDBUS_NO_SPECIALTYPES
|
||||
// and register QtCore's with us
|
||||
|
@ -84,7 +84,7 @@ int qDBusRegisterMetaType(
|
||||
void (*mf)(QDBusArgument &, const T *) = qDBusMarshallHelper<T>;
|
||||
void (*df)(const QDBusArgument &, T *) = qDBusDemarshallHelper<T>;
|
||||
|
||||
int id = qRegisterMetaType<T>(); // make sure it's registered
|
||||
int id = qMetaTypeId<T>(); // make sure it's registered
|
||||
QDBusMetaType::registerMarshallOperators(id,
|
||||
reinterpret_cast<QDBusMetaType::MarshallFunction>(mf),
|
||||
reinterpret_cast<QDBusMetaType::DemarshallFunction>(df));
|
||||
|
Loading…
Reference in New Issue
Block a user