Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt MOC Filename Collisions using multiple .pri files

Tags:

qt

qmake

In order to keep my Qt project somewhat organized (using Qt Creator), I've got one .pro file and multiple .pri files. Just recently I added a class to one of my .pri files that has the same filename as a class that already existed in a separate .pri file.

The file structure and makefiles generated by qmake appear to be oblivious to the filename collision that ensues. The generated moc_* files all get thrown into the same subdirectory (either release or debug, depending) and one ends up overwriting the other. When I try to make the project, I get several warnings that look like this:

Makefile.Release:318: warning: overriding commands for target `release/moc_file.cpp`

And the project fails to link.

Here is a simple example of what I'm talking about.

Directory structure:

+ project_dir
| + subdir1
| | - file.h
| | - file.cpp
| + subdir2
| | - file.h
| | - file.cpp
| - main.cpp
| - project.pro
| - subdir1.pri
| - subdir2.pri

Contents of project.pro:

TARGET = project
TEMPLATE = app
include(subdir1.pri)
include(subdir2.pri)
SOURCES += main.cpp

Contents of subdir1.pri:

HEADERS += subdir1/file.h
SOURCES += subdir1/file.cpp

Contents of subdir2.pri:

HEADERS += subdir2/file.h
SOURCES += subdir2/file.cpp

Is there a way to tell qmake to generate a system that puts the moc_* files from separate .pri files into separate subdirectories?

like image 237
Stephen Avatar asked Jun 02 '10 16:06

Stephen


1 Answers

In subdir1.pri try appending

MOC_DIR = "subdir1/MOCFiles"

Also for subdir2.pri give

MOC_DIR = "subdir2/MOCFiles"

It isn't tested. Just check it out. Hope it will work.

Edit 1 : Where MOCFiles is your desired folder for your moc files to get into.

Edit 2 : I just stopped mentioning with the MOC files directory since that has been asked specifically in the question. But additionally you may also have to add the following to each of the pri files. (Make sure that the folders are different for different *.pri files)

RCC_DIR = "subdir1/RCCFiles"
UI_DIR = "subdir1/UICFiles"
OBJECTS_DIR = "subdir1/ObjFiles"

I believe having multiple pri files can work without collisions by having the same file names. Since you have accepted an answer (which states it is not possible), make the above changes and give a try. Do let know if it isn't working.

like image 161
liaK Avatar answered Sep 19 '22 14:09

liaK