From 5fd8dd19ea28e2bd9cc8ce88321a401206a88f89 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 20 Jul 2012 11:02:31 +0200 Subject: [PATCH] QtWidgets: use nullary version of qRegisterMetaType("T") Using qRegisterMetaType() 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") will happily register anything. Had to add Q_DECLARE_METATYPE to QFileInfo, for QList> of QFileSystemModel to work with the partial specialisations of Q_DECLARE_METATYPE for QList, QPair. In order to synchronize this change with other modules that did their own Q_DECLARE_METATYPE(QFileInfo), a sync macro is defined that can be tested in other modules, and will later be removed again. Change-Id: I3004664e07e64cd885d5a03a57ff4e4379804aec Reviewed-by: Stephen Kelly --- src/corelib/io/qfileinfo.h | 4 ++++ src/widgets/dialogs/qfilesystemmodel.cpp | 2 +- .../widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 6b1f79a..bccecd6 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -45,6 +45,7 @@ #include #include #include +#include QT_BEGIN_HEADER @@ -156,6 +157,9 @@ typedef QList QFileInfoList; QT_END_NAMESPACE +Q_DECLARE_METATYPE(QFileInfo) +#define QT_QFILEINFO_METATYPE_DEFINED + QT_END_HEADER #endif // QFILEINFO_H diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp index ff92adb..d4dede2 100644 --- a/src/widgets/dialogs/qfilesystemmodel.cpp +++ b/src/widgets/dialogs/qfilesystemmodel.cpp @@ -1937,7 +1937,7 @@ void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QSt void QFileSystemModelPrivate::init() { Q_Q(QFileSystemModel); - qRegisterMetaType > >("QList >"); + qRegisterMetaType > >(); q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)), q, SLOT(_q_directoryChanged(QString,QStringList))); q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QList >)), diff --git a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp index f01b367..d3dd29f 100644 --- a/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp +++ b/tests/auto/widgets/itemviews/qfileiconprovider/tst_qfileiconprovider.cpp @@ -130,7 +130,6 @@ void tst_QFileIconProvider::iconType() QVERIFY(!provider.icon(type).isNull()); } -Q_DECLARE_METATYPE(QFileInfo) void tst_QFileIconProvider::iconInfo_data() { QTest::addColumn("info"); -- 2.7.4