PDA

View Full Version : Proper place to declare meta types (qRegisterMetaType())



stephelton
14th January 2013, 08:59
I have a number of types I want to declare with qRegisterMetaType. As I understand it, this must be done after QApplication::exec(). Since I don't want to be doing this all over the place, where is a good place to make all my qRegisterMetaType() calls?

anda_skoa
14th January 2013, 10:36
Depending on what you do you might not need explicit qRegisterMetaType() calls at all, e.g. when using QVariant::fromValue() it will take care of that.

In any case you don't need to delay that to the execution of the main event loop, Qt's meta type system can be used without any application object.

Cheers,
_

stephelton
14th January 2013, 16:02
I'm passing these types around in signals and slots.

anda_skoa
15th January 2013, 16:06
I assume Cross-Thread or Qt::QueuedConnection connections?
(direct connections don't need registered meta types).

In that case just register at the begin of your main function, or in the constructor of your main object/window.

Cheers,
_