Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    LabRat 'Gotcha' moc not seeing namespace.

    General and Desktop
    2
    8
    5409
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Dusty last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ?
        Guest last edited by

        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

        @

        1 Reply Last reply Reply Quote 0
        • L
          lyuts last edited by

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

          I'm a rebel in the S.D.G.

          1 Reply Last reply Reply Quote 0
          • ?
            Guest last edited by

            corrected immediately :p

            1 Reply Last reply Reply Quote 0
            • D
              Dusty last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • ?
                Guest last edited by

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

                1 Reply Last reply Reply Quote 0
                • D
                  Dusty last edited by

                  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.

                  1 Reply Last reply Reply Quote 0
                  • ?
                    Guest last edited by

                    good it worked :)

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post