views:

77

answers:

1

I'm trying to unit test a class that inherits QObject; the class itself is located up one level in my directory structure. When I build the unit test I get the standard unresolved errors if a class' MOC file cannot be found:

test.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall UnitToTest::qt_metacast(char const *)" (?qt_metacast@UnitToTest@@UAEPAXPBD@Z)

+ 2 missing functions

The MOC file is created but appears to not be linking. I've been poking around SO, the web, and Qt's docs for quite a while and have hit a wall.

How do I get the unit test to include the MOC file in the link?

====

My project file is dead simple:

TEMPLATE = app
TARGET = test
DESTDIR = .
CONFIG += qtestlib
INCLUDEPATH += . ..
DEPENDPATH += .
HEADERS += test.h
SOURCES += test.cpp ../UnitToTest.cpp stubs.cpp
DEFINES += UNIT_TEST

My directory structure and files:

C:.
| UnitToTest.cpp
| UnitToTest.h
|
\---test
    |   test.cpp       (Makefiles removed for clarity)
    |   test.h
    |   test.pro
    |   stubs.cpp
    |
    +---debug
    |       UnitToTest.obj
    |       test.obj
    |       test.pdb
    |       moc_test.cpp
    |       moc_test.obj
    |       stubs.obj

Edit: Additional information

The generated Makefile.Debug shows the moc file missing:

SOURCES       = test.cpp \
        ..\test.cpp \
        stubs.cpp debug\moc_test.cpp
OBJECTS       = debug\test.obj \
        debug\UnitToTest.obj \
        debug\stubs.obj \
        debug\moc_test.obj
+1  A: 

You need to add ../UnitToTest.h to HEADERS in the pro file.

chalup
Wow. Annoyingly simple; just as I thought it would be.
dwj