LabRat 'Gotcha' moc not seeing namespace.



  • Hello everyone!
    I am new at this, so please feel free to clout me one over the head if I'm mistaken here!

    I just found out that having a macro declared for a namespace seems to cause the moc compiler some grief.

    eg;

    @#define MY_BEGIN_NAMESPACE namespace MyNamespace {
    #define MY_END_NAMESPACE }@

    implementation:
    @#ifndef MY_TOOLS_H
    #define MY_TOOLS_H

    #include <QObject>

    #include "CommonDefinitionsQT.h"

    MY_BEGIN_NAMESPACE

    class MyTools : public QObject
    {
    ...
    }

    MY_END_NAMESPACE
    @

    causes:
    error C2653: 'MyTools' : is not a class or namespace name

    Copied from the moc source file:
    @// enum data: key, value
    79, uint(MyTools::CRC_None),
    88, uint(MyTools::CRC_8_Bit),
    @

    As you can see, I have a few Q_ENUMS() declared.
    As it seems, it is not appending the namespace to the 'MyTools class or adding a 'using namespace' declaration to the moc file.

    I'm using the latest version of QT with the Visual Studio edition.

    By the way, I got this nifty idea from the QXT library where they seem to be using this just fine, so what am I doing wrong?



  • without changing your defines, ... try this
    @
    #ifndef MY_TOOLS_H
    #define MY_TOOLS_H

    #include <QObject>

    #include "CommonDefinitionsQT.h"

    MY_BEGIN_NAMESPACE
    class MyTools;
    MY_END_NAMESPACE

    class MyTools : public QObject
    {
    ...
    };
    #endif // MY_TOOLS_H

    @



  • You missed ";" at the end of class definition.



  • corrected immediately :p



  • Thanks chetankjain for your response, I will give this a try over the weekend.

    Regarding the ";" My apologies lyuts, this was just an oversight while typing into the forum, my code of course contains a ";" at the end of the class.

    I will post a reply once I'm in a position to compile.

    Cheers.



  • its funny actually I too posted my code with a missing ; at the end of the class definition too, but corrected immediately :)



  • Well I recompiled and it works like a charm!.

    Thanks for your help on the subject. I knew it would be a rookie mistake :)

    I reckon the ";" is one of the most time wasting characters in the whole c language, I have spent hours tracking down these little you know whats... but I guess that why we like it!

    Cheers.



  • good it worked :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.