[Qt-interest] QMetaType::type succeeds or fails seemingly
Schimkowitsch Robert
Robert.Schimkowitsch at andritz.com
Fri Sep 30 13:20:04 CEST 2011
I don't store the object, I read it's properties, which are mostly
primitive types (int, double), standard Qt types (QString, QColor) or
custom-defined enums.
I don't have to know the type of a QObject to be able to read it's
properties. But I rely that the metatypes it defines (e.g. enums) are
already registered, otherwise it won't work.
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 Stephen Kelly
Sent: Friday, September 30, 2011 12:11 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] QMetaType::type succeeds or fails seemingly
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>();
>
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
#####################################################################################
This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.
Thank You.
ANDRITZ HYDRO GmbH
Rechtsform/ Legal form: Gesellschaft mit beschrankter Haftung / Corporation
Firmensitz/ Registered seat: Wien
Firmenbuchgericht/ Court of registry: Handelsgericht Wien
Firmenbuchnummer/ Company registration: FN 61833 g
DVR: 0605077
UID-Nr.: ATU14756806
#####################################################################################
More information about the Qt-interest-old
mailing list