2

I have this very strange problem while compiling the project. MOC seems to be adding a namespace to the class name being moc'ed, although it's not mentioned anywhere in the file/class.

The namespace, however, exists in a library which I use, but it's hidden far away in the header files and I don't use it in the UI files. This is what MOC generates:

const QMetaObject SmpTl::CaptureController::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_SmpTl__CaptureController,
  qt_meta_data_SmpTl__CaptureController, 0 }};

The SmpTl namespace is not mentioned anywhere in the declaration of CaptureController, but it appears in the MOC-generated .cpp file.

I'm using Visual Studio with the QT integration.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Florin
  • 2,891
  • 4
  • 19
  • 26

2 Answers2

2

I also ran into this problem. I had code that looked like this:

namespace foo {
    #ifdef _WIN32
    ...   // This code was fine
    #else
    #error Not Supported
    #endif
}

This confused MOC into thinking namespace foo never closed. Apparently, it didn't know _WIN32 was defined, and got tripped up by the fact that I forgot to put quotes around the error message. Changing it to:

#error "Not Supported"

fixed my problem.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Nathan Monteleone
  • 5,430
  • 29
  • 43
  • 1
    Ran across the exact same problem, Thanks! I have to add it only happened if the #error line contained the single quotation `'` character. Removing the `'` or enclosing the error string in double quotations `"` fixed the issue for me. – Hossein Apr 16 '14 at 14:25
0

SmpTl is the namespace CaptureController is defined in, as it was found by MOC.

The Q_OBJECT macro expands into the declaration of the staticMetaObject-variable inside your class definition (among other things it expands into). The MOC-file contains the definition of that variable.

If this is not correct, please post your Qt version and a stripped down version of your header-file.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Pieter
  • 1,191
  • 1
  • 11
  • 29
  • 1
    I found the problem, it was a missing '"' in the asm code of some header file far away in the include list. The code was #ifdef'ed only for MIPS architecture, so the compiler didn't complain about the missing ", but somehow MOC got confused. – Florin Apr 22 '10 at 09:47