It seems like something is going wrong when pointer values transcend between C++ and QML world. I am using the plain old fromValue()
and value()
to convert to and from void *
, and it does work as expected as long as the variant stays on the C++ side.
The moment it is returned to QML, it now resolves to null
, and when passed back to C++, the variant type is changed from void *
to std::nullptr_t
and the value is null.
returning 0x3ba5b10 // created
converting to qvariant 0x3ba5b10 // converting
converted QVariant(void*, 0x3ba5b10) 0x3ba5b10 // now variant, testing value() - all good
qml: null // in qml
received QVariant(std::nullptr_t, (nullptr)) 0x0 // back in c++
I am using:
Q_DECLARE_METATYPE(void*)
qRegisterMetaType<void*>();
Any clue as to what is going on here?
Edit: it keeps even more strange, I get it to work by casting the pointer values to 64 bit uint and back, but upon the transition to QML, the type info gets messed up, in C++ the variant is of type qulonglong
, arriving back from QML it is now a double
, hence the suspicion it might round something and mess up the pointer value.
Edit 2: note that the question is not about recommending practices but about why this doesn't work as expected and observed prior to reaching QML.