<Resolved> Convert QHash <long long int, QList<long long int>> into a QVariant
-
Hello Guys:
Another Conversion pain questionI have QHash <long long int, QList<long long int> > object which I need to convert to a QVariant. But I am unable to do so. Kindly anyone can tell me what i need to be doing in this case.
I really dont want to a use QHash <QString , QList <QVariant> > instead of QHash <long long int, QList<long long int> >
Regards
The Illiterate
-
@
// Setting:QVariant storage = QVariant::fromValue(yourHashObjectPointer);
// Getting:
QHash <long long, QList<long long> > result = storage.value<QHash <long long, QList<long long> > >();
@ -
Thanks Sierdzio, but that did not work for me. I was still getting compilation erros
So I tried Registering my QHash type.@typedef QHash<long long int, QList<long long int>> HashMap;
} /namespace custom/
} /namespace my/
Q_DECLARE_METATYPE( my::custom::HashMap );@but still gives me compilation errors:
@usr/include/qt4/QtCore/qmetatype.h: In function 'void* qMetaTypeConstructHelper(const T*) [with T = QHash<long long int, QList<long long int> >]':
usr/include/qt4/QtCore/qmetatype.h:196:25: instantiated from 'int qRegisterMetaType(const char*, T*) [with T = QHash<long long int, QList<long long int> >]'
../xxxxx/xxxxx/xxxxx.hpp:xx:1: instantiated from here
usr/include/qt4/QtCore/qmetatype.h:141:22: error: invalid use of incomplete type 'struct QHash<long long int, QList<long long int> >'
usr/include/qt4/QtCore/qdatastream.h:66:37: error: declaration of 'struct QHash<long long int, QList<long long int> >'
usr/include/qt4/QtCore/qmetatype.h:142:43: error: invalid use of incomplete type 'struct QHash<long long int, QList<long long int> >'
usr/include/qt4/QtCore/qdatastream.h:66:37: error: declaration of 'struct QHash<long long int, QList<long long int> >'
usr/include/qt4/QtCore/qmetatype.h: In function 'void qMetaTypeDeleteHelper(T*) [with T = QHash<long long int, QList<long long int> >]':
usr/include/qt4/QtCore/qmetatype.h:198:22: instantiated from 'int qRegisterMetaType(const char*, T*) [with T = QHash<long long int, QList<long long int> >]@ -
Hi,
You might have forgotten to include QHash. Otherwise it the typedef/Q_DECLARE_METATYPE combo works well.
-
Thanks SGaist. You are right :) I wasted a lot of time assuming one of the many included header files must already contains include for QHash, but they did not :(
Thanks a lot :)
Regards
The Illiterate -
Qt headers use forward declaration to speed up compilation time. It's good practice to include everything that you declare. Avoiding module includes is also a good idea (so, no <QtCore> but <QString>).
-
Thanks sierdzio for the valuable tip :)
Regards
The Illiterate -
You're welcome !
Don't forget to set the thread's title to solved :) -
Done! Thanks:)