P
P
Pavel K2015-08-01 01:28:27
Qt
Pavel K, 2015-08-01 01:28:27

Why is qvariant_cast acting weird?

Greetings!
In general, there is a certain pointer to a class (for example, ProductItem), you need to pass it using QVariant,
I pass it like this:

ProductItem * item = new ProductItem(this);
QVariant MyClass::getItem()
{
return qVariantFromValue(static_cast<WBaseItem*>(item));
}

this is simplified, of course, the class is not destroyed after exiting the function and I guarantee that it exists.
further in the right place I already cast:
WBaseItem * item = qvariant_cast<WBaseItem*>(getItem());

So, item is always 0, although if the call qDebug()<<getItem();is explicitly specified
QVariant(WBaseItem*, ProductItem(0x1665e70) )
ProductItem is inherited from WBaseItem. If you do not transfer through QVariant, then through dynamic_cast everything goes fine.
Tell me, please, how to transfer correctly?
PS About Q_DECLARE_METATYPE(WBaseItem*) read, made, does not plow.
It is extremely strange that in some other cases it works fine.
In them, other classes inherit the same from WBaseItem but are brought to it normally, but in the current one they don’t want to, although the class itself, which is inherited, is simple ... some kind of devilry.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2015-08-01
@PavelK

It was decided in 3 hours of wasted time.
It was in the virtual class, qvariant_cast apparently did not know how to process it, although canConvert gave out that it could.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question