[Qt-interest] Custom type in a list?
Peter
pgeorges at gmail.com
Tue Nov 3 14:45:04 CET 2009
Hi, I understand how to set up a custom type and store it in a QVariant
after looking at this http://qt.nokia.com/doc/4.5/tools-customtype.html
However, I am stuck as I need to store and retrieve a list of custom types
and am unsure of what I am doing wrong.
Here is an example:
//custom type
class CustomType
{
public:
CustomType();
CustomType(QString& name);
CustomType(const CustomType& other);
virtual ~ CustomType();
QString name() const;
private:
QString m_name;
};
//declaring the metatype
Q_DECLARE_METATYPE(CustomType)
Q_DECLARE_METATYPE(CustomTypeList)
I then create a custom type in another class and try to save and restore the
state:
typedef QList<CustomType> CustomTypeList;
CustomTypeList m_customtype;
settings.setValue("CustomType", QVariant::fromValue(m_customtype));
m_customtype = settings.value("CustomType").value<CustomTypeList>();
Now, when I do this, I end up with the following error from the saveState:
QVariant::save: unable to save type 256.
Does anyone know what exactly I am doing wrong?
Cheers,
Peter.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091104/948c5a0c/attachment.html
More information about the Qt-interest-old
mailing list