PDA

View Full Version : QVariant, QVariantMap, and QFileInfoList



themolecule
13th September 2007, 05:15
I am trying to do something like this:



QVariantMap payload;
QDir d = "/";
payload["children"] = d.entryInfoList();


but the compiler doesn't seem to have an 'operator=':



fileserverWindow.cpp:50: error: no match for 'operator=' in '(+ payload)->QMap<Key, T>::operator[] [with Key = QString, T = QVariant](((const QString&)(& QString(((const char*)"children"))))) = QDir::entryInfoList(QFlags<QDir::Filter>, QFlags<QDir::SortFlag>) const(QFlags<QDir::Filter>(NoFilter), QFlags<QDir::SortFlag>(NoSort))'


I know that qRegisterMetaType<QFileInfo>("QFileInfo"); goes in there somewhere, plus the Q_DECLARE_METATYPE ( QFileInfo ) but I can't seem to figure out where... no combination works. I think Q_DECLARE_METATYPE ( QFileInfo ) goes at the top, and qRegisterMetaType goes in the function, before the assignment.

How do I assign QFileInfoList to a QVariant?

themolecule
13th September 2007, 05:28
I tried this:



payload["children"] = qVariantFromValue(d.entryInfoList());


but then there's an error:



qmetatype.h:183: error: 'qt_metatype_id' is not a member of 'QMetaTypeId<QFileInfoList>'


how do I register the type?

spud
13th September 2007, 07:00
Have you tried Q_DECLARE_METATYPE ( QFileInfoList ), qRegisterMetaType<QFileInfoList>("QFileInfoList")?