qt - And so a QVariant instantiation silently registeres a (previously declared) metatype -


take program (adapted exploratory test-case, noticed custom metatype bahaves if registered, although qregistermetatype had not been called):

#include <qmetatype> #include <qvariant>  #include <iostream>  class c1 { };  q_declare_metatype(c1)   int main() {     std::cout << qmetatype::type("c1") << std::endl;      qvariant v = qvariant::fromvalue<c1>(c1());      std::cout << qmetatype::type("c1") << std::endl;      return 0; } 

this outputs:

0 256 

(and further tests show metatype indeed registered -- can construct'ed (even in places q_declare_metatype(..) not visible), etc)

is behaviour well-known? relied on? (probably not, attempting failing test following "official" rule register metatype first got me puzzled, hence question)

p.s. of course, 1 can see qregistermetatype called within q_declare_metatype(..), question still holds (at least to).

thanks in advance.

q_declare_metatype doesn't call qregistermetatype, defines function does. qvariant::fromvalue<c1> calls qregistermetatype indirectly, calling defined function.

the documentation suggests calling qregistermetatype needed things queued connections.

which means don't need call qregistermetatype before using qvariant template functions type (but q_declare_metatype has called in each compilation unit template functions used or compilation fail).


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -