[Interest] Access QVariant's raw data
Thiago Macieira
thiago.macieira at intel.com
Sun Apr 8 05:16:34 CEST 2012
On domingo, 8 de abril de 2012 04.24.01, Jonas Gehring wrote:
> Hi there,
>
> Does anybody know a way to access the raw data inside a QVariant?
variant.data_ptr();
> Just for clarification: I know about Q_DECLARE_METATYPE,
> qRegisterMetaType etc. I'm currently passing user-defined type
> that are boxed inside a QVariant across different threads, and
> at some point I'm invoking a slot initially defined by the
> caller. Ideally, I'd like to do:
>
> QVariant result = ...; // Just received from thread
> QMetaMethod method = ...; // Pass the result to this method
> method.invoke(receiver, QGenericArgument(result.typeName(),
> result.value<void *>()));
You're not supposed to use QGenericArgument directly. Use Q_ARG.
> result.value<void *>() returns a NULL pointer, although the
> type name (and the actual value) are correct. Is there
> another way or am I missing something?
You're missing something.
value<void *>() first checks if the type in the variant is equal to
QMetaType::VoidStar. If it isn't -- and you gave me no reason to believe it is
-- then it returns 0.
So, from what I can tell, the code you wrote is working exactly like it's
supposed to. The problem is that you wrote code you weren't supposed to:
you're supposed to use Q_ARG.
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
Intel Sweden AB - Registration Number: 556189-6027
Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120408/8d5d5b76/attachment.sig>
More information about the Interest
mailing list