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

Flavio Castelli flavio at castelli.name
Fri Mar 19 12:13:04 CET 2010


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



More information about the Qt-interest-old mailing list