[Qt-interest] Custom type in a list?

J-P Nurmi jpnurmi at gmail.com
Fri Nov 6 10:48:48 CET 2009


On Fri, Nov 6, 2009 at 11:27 AM, Peter <pgeorges at gmail.com> wrote:
> 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.

Hi,

See http://wiki.qtcentre.org/index.php?title=Using_custom_data_types_with_Qt

--
J-P Nurmi




More information about the Qt-interest-old mailing list