[Qt-interest] Is it possible to discover if a custom type stored into a QVariant inherits the QObject class?

André Somers andre at familiesomers.nl
Fri Mar 19 12:43:05 CET 2010


Perhaps a last resort:
Create your own registration mechanism replacing or being used next to
Q_REGISTER_METATYPE. Not ideal, but it should be doable. You can then
register anything you want, including if the type inherits QObject.

André

-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens Flavio Castelli
Verzonden: vrijdag 19 maart 2010 12:13
Aan: qt-interest at trolltech.com
Onderwerp: Re: [Qt-interest] Is it possible to discover if a custom type
stored into a QVariant inherits the QObject class?

On Friday 19 March 2010 11:47:04 Andreas Pakulat wrote:
> You can't do that, QVariant merely stores a void* internally, so you need
> to tell it how to get something useful out of that again. Hence you have
to
> know what was originally put into the variant.

Yep, looking at QVariant doc&code there's no way to achieve that.

> Not sure wether dynamic_cast
> works that way, but you could ask the QVariant for a void* and then try to
> use dynamic_cast<QObject*> to determine wether its a QObject or not. i.e.
> do the check yourself instead of letting QVariant do it.

It doesn't allow void* as arguments. I would have to use a static_cast or a 
reinterpret_cast but they don't make run-time checks.

I looked at all the Meta-Object system documentation but I didn't find a 
solution for this problem. I just hoped I had missed something...

Cheers
Flavio
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest





More information about the Qt-interest-old mailing list