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

Tomasz Olszak olszak.tomasz at gmail.com
Mon Jul 29 18:25:04 CEST 2019


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;
}


niedz., 28 lip 2019 o 06:22 Thiago Macieira <thiago.macieira at intel.com>
napisaƂ(a):

> On Friday, 26 July 2019 17:35:03 PDT Nikos Chantziaras wrote:
> > I didn't (although I use Q_ENUM, but it does the same job.) But there's
> > no constructor to put qRegisterMetaType() in. It's an enum. There's no
> > constructor. Some enums are in a namespace, some are in a class, but
> > even with an enum that is in a class, users of can just use the enum in
> > their own signals/slots prior to instantiating the class that declares
> > the enum. It will stay unregistered until the first instance of the
> > class is created.
> > ____________________
>
> I meant in the class it's most likely to be used in.
>
> This is only required when referring to it by name, such as in old-style
> signal-slot connection, QML, D-Bus, etc.
>
> Loading it into a QVariant automatically registers, as QVariant calls
> qMetaTypeId<Enum>() to get the metatype ID.
>
> --
> Thiago Macieira - thiago.macieira (AT) intel.com
>   Software Architect - Intel System Software Products
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190729/71383f0a/attachment.html>


More information about the Interest mailing list