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

Using qRegisterMetaType<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>("T")
will happily register anything.

Had to add Q_DECLARE_METATYPE to QFileInfo, for
QList<QPair<QString,QFileInfo>> 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 <stephen.kelly@kdab.com>
This commit is contained in:
Marc Mutz 2012-07-20 11:02:31 +02:00 committed by Qt by Nokia
parent 790aca0ea1
commit 5fd8dd19ea
3 changed files with 5 additions and 2 deletions

View File

@ -45,6 +45,7 @@
#include <QtCore/qfile.h>
#include <QtCore/qlist.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qmetatype.h>
QT_BEGIN_HEADER
@ -156,6 +157,9 @@ typedef QList<QFileInfo> QFileInfoList;
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QFileInfo)
#define QT_QFILEINFO_METATYPE_DEFINED
QT_END_HEADER
#endif // QFILEINFO_H

View File

@ -1937,7 +1937,7 @@ void QFileSystemModelPrivate::_q_resolvedName(const QString &fileName, const QSt
void QFileSystemModelPrivate::init()
{
Q_Q(QFileSystemModel);
qRegisterMetaType<QList<QPair<QString,QFileInfo> > >("QList<QPair<QString,QFileInfo> >");
qRegisterMetaType<QList<QPair<QString,QFileInfo> > >();
q->connect(&fileInfoGatherer, SIGNAL(newListOfFiles(QString,QStringList)),
q, SLOT(_q_directoryChanged(QString,QStringList)));
q->connect(&fileInfoGatherer, SIGNAL(updates(QString,QList<QPair<QString,QFileInfo> >)),

View File

@ -130,7 +130,6 @@ void tst_QFileIconProvider::iconType()
QVERIFY(!provider.icon(type).isNull());
}
Q_DECLARE_METATYPE(QFileInfo)
void tst_QFileIconProvider::iconInfo_data()
{
QTest::addColumn<QFileInfo>("info");