How To Save Custom Type To QSettings?
<p>I'm trying to save a custom type to QSettings but I'm getting an error at runtime.  Here's the class I'm trying to save:</p>

<pre><code>#ifndef TESTCLASS_H
#define TESTCLASS_H

#include &lt;QMetaType&gt;
#include &lt;QString&gt;

class TestClass
{
public:
    QString testString;
    int testInt;
    bool testBool;
};

Q_DECLARE_METATYPE(TestClass)

#endif
</code></pre>

<p>And here's the code to save an instance of the class to QSettings</p>

<pre><code>TestClass test;
test.testString = "Test";
test.testInt = 10;
test.testBool = false;

settings.setValue("TestGroup/TestVal", QVariant::fromValue(test));
settings.sync();
</code></pre>

<p>The error I get at runtime is:</p>

<pre><code>QVariant::save: unable to save type 'TestClass' (type id: 1032).

ASSERT failure in QVariant::save: "Invalid type to save", file kernel\qvariant.cpp, line 2124
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
</code></pre>

<p>According to the documentation, the class must provide a default constructor, destructor and a copy constructor.  For this class the automatically generated constructor, destructor and copy constructors would be sufficient, so I haven't provided one (though I did try it anyway to see if that was the problem).  I've also used Q_DECLARE_METATYPE() so the class is known to QMetaType, so as far as I can tell I've met the requirements to use the class with QVariant.</p>

<p>What am I missing?</p>