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

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Interest mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to