[Interest] [SPAM] Is it safe to call qRegisterMetaType() before main()?

Hamish Moffatt hamish at risingsoftware.com
Tue Jul 23 01:15:05 CEST 2019


On 22/7/19 10:56 pm, Nikos Chantziaras wrote:
> In order to avoid calling qRegisterMetaType() in main() (with the 
> possibility of forgetting to do so,) I instead call it before the 
> program enters main(), in the implementation file of whoever is the 
> owner of the type. There's several ways to do this, I just use a lambda:
>
> namespace {
> char unused = [] {
>     qRegisterMetaType<MyClass::MyEnum>();
>     return 0;
> }();
> }
>
> It "seems to work fine," but is this safe though?


Why not put them in a static function in each file, and use 
Q_COREAPP_STARTUP_FUNCTION to have Qt call it for you at the right time?



Hamish




More information about the Interest mailing list