Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, July 2007
Q_ENUMS: howto register 'external' enums


Message 1 in thread

Hi,

 

I'm facing the following problem:

I have a lot of classes, and many of them are using the same enums. All
these enums are declared in a separate header file.

I must register these enums with Q_ENUMS in two of my classes. My
current solution is very ugly, but it was the only way I could make it
work: I've duplicated these enums mit Copy/Paste into the header file of
those classes. It means, that my enums are being declared in three
times: in the separate header, and in the header of the classes, where
they must be registered. :(((

 

Does anyone have a better solution? Any advice would be appriciated.

 

Thanks

Laszlo

 

 


Message 2 in thread

Federics Laszlo a écrit :

> Hi,
>
>  
>
> I'm facing the following problem:
>
> I have a lot of classes, and many of them are using the same enums. 
> All these enums are declared in a separate header file.
>
> I must register these enums with Q_ENUMS in two of my classes. My 
> current solution is very ugly, but it was the only way I could make it 
> work: I've duplicated these enums mit Copy/Paste into the header file 
> of those classes. It means, that my enums are being declared in three 
> times: in the separate header, and in the header of the classes, where 
> they must be registered. :(((
>
>  
>
> Does anyone have a better solution? Any advice would be appriciated.
>
>  
>
> Thanks
>
> Laszlo
>
>  
>
>  
>
maybe it's stupid but... why don't you do, like in qt  qnamespace.h ?
you register and declare you enums and just include this .h in class 
file you want to use them.

using this solution and namespace to control if it's a "common" enum or 
your "class" enum that you want to use.


AppNamespace
{
    Q_ENUMS(ToolButtonStyle )
//etc.......

  
 enum ToolButtonStyle {
        ToolButtonIconOnly,
        ToolButtonTextOnly,
        ToolButtonTextBesideIcon,
        ToolButtonTextUnderIcon
    };

}

Message 3 in thread

On 7/31/07, veronique.lefrere@xxxxxx <veronique.lefrere@xxxxxx> wrote:
>  maybe it's stupid but... why don't you do, like in qt  qnamespace.h ?
> you register and declare you enums and just include this .h in class file
> you want to use them.

Qt uses some magic to make this work:

#ifndef Q_MOC_RUN
namespace
#else
class Q_CORE_EXPORT
#endif
Qt {
#ifdef Q_MOC_RUN
    Q_OBJECT
    Q_ENUMS(Orientation TextFormat BackgroundMode DateFormat
ScrollBarPolicy FocusPolicy ContextMenuPolicy CaseSensitivi
ty LayoutDirection ArrowType ShortcutContext)

Looking at this appears that sometimes the namespace is treated as a
namespace, and other times as class. I don't see any reason why this
shouldn't work though it seems a bit evil.

Cheers

Rich.

--
 [ signature omitted ] 

Message 4 in thread

Thanks a lot, it will work.

Laszlo

-----Original Message-----
From: Richard Moore [mailto:richmoore44@xxxxxxxxx] 
Sent: Tuesday, July 31, 2007 3:38 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: [SPAM] - Re: Q_ENUMS: howto register 'external' enums -
Bayesian Filter detected spam

On 7/31/07, veronique.lefrere@xxxxxx <veronique.lefrere@xxxxxx> wrote:
>  maybe it's stupid but... why don't you do, like in qt  qnamespace.h ?
> you register and declare you enums and just include this .h in class
file
> you want to use them.

Qt uses some magic to make this work:

#ifndef Q_MOC_RUN
namespace
#else
class Q_CORE_EXPORT
#endif
Qt {
#ifdef Q_MOC_RUN
    Q_OBJECT
    Q_ENUMS(Orientation TextFormat BackgroundMode DateFormat
ScrollBarPolicy FocusPolicy ContextMenuPolicy CaseSensitivi
ty LayoutDirection ArrowType ShortcutContext)

Looking at this appears that sometimes the namespace is treated as a
namespace, and other times as class. I don't see any reason why this
shouldn't work though it seems a bit evil.

Cheers

Rich.

--
 [ signature omitted ]