[Qt-interest] QMetaType::type succeeds or fails seemingly

Stephen Kelly steveire at gmail.com
Fri Sep 30 12:10:34 CEST 2011


Schimkowitsch Robert wrote:

> I can't use qRegisterMetaType<MyType>(), because I don't know the type
> at compile time.

If MyType is-a QObject, then you should store it as a QObject in the 
QVariant, don't store it as MyType and don't even use 
QDECLARE_METATYPE(MyType*).




> The type is defined inside a library, and I only get it by iterating
> through the properties of a QObject-based class defined within that
> library.
> 
> My test code knew the type, but that was just test code.
> In my real app, I try to set the properties of an unknown QObject-based
> class from an input XML file.
> I iterate through all properties. If they are an enumeration type, I get
> the QMetaEnum information. If the string from the XML file matches any
> of the enum keys, I assign the enum that value.
> 
> What would really help me would be some method I could call on the
> QObject that would ensure all DECLARE_METATYPE enums related to that
> object are resolved.
> 
> Kind Regards
> 
> Robert Schimkowitsch
> 
> -----Original Message-----
> From: qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.com
> [mailto:qt-interest-bounces+robert.schimkowitsch=andritz.com at qt.nokia.co
> m] On Behalf Of Thiago Macieira
> Sent: Wednesday, September 28, 2011 10:31 AM
> To: qt-interest at qt.nokia.com
> Subject: Re: [Qt-interest] QMetaType::type succeeds or fails seemingly
> 
> On Wednesday, 28 de September de 2011 10:15:34 Stefan Majewsky wrote:
>> On Mon, Sep 26, 2011 at 4:50 PM, Schimkowitsch Robert
>> 
>> <Robert.Schimkowitsch at andritz.com> wrote:
>> > Which brings up the question: When does Q_DECLARE_METATYPE run, and
> how
>> > do I make it run?
>> 
>> Looking at the definition of Q_DECLARE_METATYPE, in
>> include/QtCore/qmetatype.h, you should be able to "make it run" by
>> 
>>     (void) QMetaType<MyType>::qt_metatype_id();
>> 
>> before the QMetaType::type() call. I don't know about the ABI
>> stability policy for this macro, but I think this should be
>> binary-compatible until at least Qt 5.
> 
> You can use the documented way:
> qRegisterMetaType<MyType>();
> 





More information about the Qt-interest-old mailing list