[Qt-interest] QMetaType question

Thiago Macieira thiago at kde.org
Sun Jan 17 19:28:44 CET 2010


Em Domingo 17. Janeiro 2010, às 16.49.18, JD Guzman escreveu:
> Good afternoon,
> 
> I was trying to work with QMetaType to create a instance of a class that
> I have made.  I followed the documentation and have gotten to the point
> that I am doing the following:
> 
>     int id = QMetaType::type("MyClass");
> 
>     if (id != 0)
>     {
>         qDebug("MyClass found ...");
>         void* controller = QMetaType::construct(id);
>     }
> 
> I do get the "MyClass found ..." message and there are no errors so I am
> assuming that everything is good up to there.  My question is where do I
> go from here?  Since controller is type void* I cannot call any of the
> functions in MyClass.  I tried casting but that didn't work either.

That's all there is. You can cast it to MyClass* and it should work:

MyClass *c = static_cast<MyClass *>(controller);

The only two other operations in QMetaType you can do are copy (construct with 
a non-0 second argument) and destroy.

Anything else is only available through the casting.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100117/37ec5a8f/attachment.bin 


More information about the Qt-interest-old mailing list