[Qt-interest] Custom type in a list?

Peter pgeorges at gmail.com
Fri Nov 6 10:27:53 CET 2009


Anyone have any ideas?

On Wed, Nov 4, 2009 at 12:45 AM, Peter <pgeorges at gmail.com> wrote:

> 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/20091106/04f6a75a/attachment.html 


More information about the Qt-interest-old mailing list