I have run into a problem with how qmake generates the targets for moc files, when I have the same file name in different subdirectories.
For instance, in my .pro file, I have the following:
DESTDIR = Objs
MOC_DIR = Mocs
UI_DIR = Uics
RCC_DIR = Rccs
HEADERS += Images/Types.h
HEADERS += Images/Cache.h
HEADERS += Sounds/Types.h
HEADERS += Sounds/Cache.h
SOURCES += Images/Cache.cpp
SOURCES += Sounds/Cache.cpp
CONFIG += warn_on staticlib
TEMPLATE = lib
DESTDIR = Objs
MOC_DIR = Mocs
UI_DIR = Uics
RCC_DIR = Rccs
HEADERS += Images/Types.h
HEADERS += Images/Cache.h
HEADERS += Sounds/Types.h
HEADERS += Sounds/Cache.h
SOURCES += Images/Cache.cpp
SOURCES += Sounds/Cache.cpp
CONFIG += warn_on staticlib
TEMPLATE = lib
To copy to clipboard, switch view to plain text mode
The Images/Cache.h and Sounds/Cache.h both include class definitions that inherit from QObject in order to provide signals and slots. When I run qmake on the file, it generates the following for the moc targets inside the Makefile:
Mocs/moc_Cache.cpp: Images/Types.h \
Images/Cache.h \
/usr/lib/qt4/bin/moc
/usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Images/Cache.h -o Mocs/moc_Cache.cpp
Mocs/moc_Cache.cpp: Sounds/Types.h \
Sounds/Cache.h \
/usr/lib/qt4/bin/moc
/usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Sounds/Cache.h -o Mocs/moc_Cache.cpp
Mocs/moc_Cache.cpp: Images/Types.h \
Images/Cache.h \
/usr/lib/qt4/bin/moc
/usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Images/Cache.h -o Mocs/moc_Cache.cpp
Mocs/moc_Cache.cpp: Sounds/Types.h \
Sounds/Cache.h \
/usr/lib/qt4/bin/moc
/usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) Sounds/Cache.h -o Mocs/moc_Cache.cpp
To copy to clipboard, switch view to plain text mode
This clearly shows a problem, which make warns about when it is run. The moc_Cache.cpp target is generated from two different files. I'm looking for suggestions about whether there might be easy ways to fix the output, or if I need to start having different names for every file in my projects.
Along the way, I did see the "new_moc" example in the qmake advanced configuration section, that would appear to offer a way to fix this, but I was unable to get it to find only the files that should have moc run on them, as opposed to all header files.
Bookmarks