Int qRegisterMetaType (const char *typeName) & int qRegisterMetaType() difference



  • Hi! Could you please explain me what is the difference between them?



  • qRegisterMetaType(const char *) enables you to add a name to the meta type, so you can get the type by name as well. Probably useful on some platforms.



  • It is definitely not the solely difference between them. Because with second version I have complaining in runtime in queued signals/slots. When I emit signal in one thread and capture it in other one with QSignalSpy I have a complaint when try to cast an argument to my type. I have no complaints with 1st version.



  • I strongly advise to always use version taking name, in some places in Qt the name is checked to provide additional functionality. It is extremely important when you use QtDeclarative, QtScirpt or QtDbus.

    Try to use Q_DECLARE_METATYPE() macro instead, it is superior in many aspects (for example it will work with QVariant too).



  • Well, I've actually found the answer on this question and even wrote article about it. It is in Russian though.

    >> Try to use Q_DECLARE_METATYPE() macro instead

    You can't use it instead you should use it in conjunction. qRegisterMetaType complements Q_DECLARE_METATYPE.

    Version with name and without name are really the same(one is called from another actually). With only one difference in behavior: when you register type which is located in namespace it will register type with namespace prefix. And qRegisterMetaType with name argument allows you to register name without namespace prefix. That is it.



  • You are fast, I was about to correct my comment :-)



  • [quote author="ixSci" date="1334222143"]
    Version with name and without name are really the same(one is called from another actually). With only one difference in behavior: when you register type which is located in namespace it will register type with namespace prefix. And qRegisterMetaType with name argument allows you to register name without namespace prefix. That is it.[/quote]

    Could you perhaps clarify the above (bold) a little bit more? Which version are you talking about there exactly?



  • qRegisterMetaType() registers type with namespace prefix, if any. You can't change it.
    qRegisterMetaType (const char *typeName) allows to set particular name, so you can register type w/o namespace prefix


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.