Qt MOC Collision File Name Using Multiple .pri Files

In order for my Qt project to be organized a little (using Qt Creator), I have one .pro file and several .pri files. Most recently, I added a class to one of my .pri files, which has the same file name as the class that already exists in a separate .pri file.

The file structure and make files created by qmake do not appear to address the file name conflict that arises. The generated moc_ * files are all transferred to the same subdirectory (either debugged or debugged, depending), and one of them overwrites the other. When I try to create a project, I get a few warnings that look like this:

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

And the project is not connected.

Here is a simple example of what I am saying.

Directory structure:

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

The 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 any way to tell qmake to create a system that puts moc_ * files from separate .pri files in separate subdirectories?

+7
qt qmake
source share
3 answers

It is best to ensure that all files have a unique name. There are other tools besides qmake, which also break when you try to do what you do; you can also potentially make this confusing for yourself (for example, understanding that #include "file.h" makes it harder).

+3
source share

In subdir1.pri try adding

 MOC_DIR = "subdir1/MOCFiles" 

Also for subdir2.pri specify

 MOC_DIR = "subdir2/MOCFiles" 

It is not verified. Just check it out. Hope it works.

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

Edit 2: I just stopped mentioning the MOC file directory, as it was asked specifically in the question. But, in addition, you may also need to add the following to each of the pri files. (make sure the folders are different for different * .pri files)

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

I believe that several pri files can work without collisions, having the same file names. Since you accepted the answer (which claims this is not possible), make the above changes and try. Let me know if it works.

+4
source share

I have tried this before. The short answer is to name them differently. Another answer would be to treat each subdirectory as a separate library with its own .pro file and use the subdirs type to compile all library directories.

If you really want to research the complete answer, you can specify the tool that will be used for moc. In this situation, you can change the name so that several different files use a slightly different name. However, you also need to make sure that each file with different names is added to the list of files for compilation and link, and that the originally named moc file is missing (or your assembly will fail).

0
source share

All Articles