How can I use cascaded namespaces in moc files?

1k views Asked by At

I'm currently writing a small application with Qt (4.7). And I use nested namespaces like

namespace app {
    namespace core {
        class CoreClass {...}
    }
}

Because I'm a litte bit lazy, I am using symbols for shortcuts that hold the opening and closing namespace declarations:

APP_START
    class CoreClass {...}
APP_END

The symbols are defined in a global header file.

So far, so good. It works perfect on compile time. But when the moc generator creates the moc files, it missed the namespace declarations and the methods are generated in the standard namespace. When don't use the symbols, everything works fine.

When I redefine the QT_BEGIN_MOC_NAMESPACE symbol, the compiler throws a redefine-warning on every include. This works indeed, but I think it's not really nice.

Is there a better solution for this issue?

1

There are 1 answers

2
Sohail On

First I'd find out why moc isn't doing the macro substitution. Maybe -I is wrong?

Second, you can try the -D parameter to moc. Maybe something like: moc "-DAPP_BEGIN=namespace app { namespace core {"