开发者

Bad linking in Qt unit test -- missing the link to the moc file?

I'm trying to unit test a class that inherits QObject; the class itself is located up one level in my directory str开发者_JAVA技巧ucture. 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜