[Interest] emi enum type that defined in class of namespace

Thiago Macieira thiago.macieira at intel.com
Tue Feb 25 02:37:30 CET 2020


On Monday, 24 February 2020 17:22:16 PST nus1998 wrote:
> Hi,
> 
> 
> I have a piece of code like this:
> namespace FOO_NS {
> class FOO_CLASS : public QObject
> {
>     Q_OBJECT
> public:
>     enum FOO_EM { EM_A, EM_B };
> 
> signals:
>     void trigger(FOO_EM foo);
> }
> }
> the signals doesn't work obviously as enum doesn't be registered. if I add
> Q_ENUM(FOO_EM) after the enum declaration, it doesn't work too. If I add
> Q_NAMESPACE and Q_ENUM_NS(FOO_EM) before/after the enum declaration
> respectively,  some errors encounters like "'const QMetaObject
> FOO_NS::FOO_CLASS::staticMetaObject' conflicts with a previous
> declaration". now the only work way that I have tried is that using
> qRegisterMetaType<FOO_NS::FOO_CLASS::FOO_EM>() to registered it, and change
> "void trigger(FOO_EM foo)" to "void trigger(FOO_NS::FOO_CLASS::FOO_EM
> foo)", which looks a bit ugly and I want to know is there more concise way
> to achieve it.

If you want to use the old-style (text-based) connection, you must type the 
full classification of the enum:

  void trigger(FOO_NS::FOO_CLASS::FOO_EM);

Ugly but required.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products





More information about the Interest mailing list