[Interest] Is it safe to call qRegisterMetaType() before main()?
Tomas Konir
tomas.konir at gmail.com
Mon Jul 29 22:50:19 CEST 2019
po 29. 7. 2019 v 21:00 odesÃlatel Nikos Chantziaras <realnc at gmail.com>
napsal:
> The linker might remove it from the executable when linking statically,
> because 'registerHelper' is not referenced anywhere.
>
>
> On 29/07/2019 19:25, Tomasz Olszak wrote:
> > What's is the cons of putting something like that in anonymous namespace
> > instead of constructor?
> >
> > namespace {
> > struct RegisterHelper
> > {
> > RegisterHelper()
> > {
> > qRegisterMetaType<MyClass>();
> > qRegisterMetaType<MyEnum>();
> > qRegisterMetaTypeStreamOperators<MyClass>();
> > }
> > };
> > static RegisterHelper registerHelper;
> > }
>
Hi,
I'm using C constructor attribute with no problems.
Code like below at each class cpp file.
static void constructor() __attribute__((constructor));
static void constructor(){
qmlRegisterType<ClassName>("ClassName", 1, 0, "ClassName");
}
Maybe it helps.
Tom
--
Tomas Konir
Czech Republic
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190729/8dbb867d/attachment.html>
More information about the Interest
mailing list