[Qt-interest] Calling qRegisterMetaType on static initialization

Karl Krach mailinglists at blueSpirit.la
Sat Jan 21 18:06:35 CET 2012


Hello,

"Static member variables are initialized before the 'real program'
(main()) starts" - right? At least this is how I understand
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.14

So I used this nice trick for calling qRegisterMetaType:

###################### in the HEADER #########################

class MyClass
{
	static int GetMetaID() { return m_sMetaID; }
	static int RegisterMetaType();
	static const int s_iMetaID:
};

#################### in the CPP ##############################

const int MyClass::s_iMetaID = MyClass::RegisterMetaType();

int MyClass::RegisterMetaType()
{
	printf( "MyClass\n" ); fflush( stdout );
	return qRegisterMetaType<MyClass>( "MyClass" );
}

##############################################################

This is how it was working some time ago - and not it fails. The
RegisterMetaType() is only called, when I call GetMetaID() - and not before.

Does it depend on the GCC version? Am I wrong with my precondition?

Best regards,

Charly



More information about the Qt-interest-old mailing list