Please nominate your Qt Champions for 2021!

Specify directories for UIC, MOC, and Object Files for each Module in an Application

  • Greetings.

    I have an application composed of several modules. Each module is in a different namespace, and the source files of each module are grouped into subdirectories with the name of the corresponding namespace.

    For example: a module that implements operations of mathematical morphology is in the namespace "Morph". All class files (.h, .cpp, etc.) of this module are in the "morph" subdirectory within the application's home directory.

    In this way, there are different classes that have the same name, but belong to different namespaces and subdirectories. As there are classes of the same name however, I have problems compiling since the outputs of uic and moc for different classes are written to the same file (there is overwriting). The same happens with object files (.o) corresponding to two classes of the same name.

    I want to know how to specify different subdirectories for the outputs of the uic, moc and object files for each class in my application.

    Currently all the output of the uic, moc and files object of my application go the directories named "uic", "moc" and "obj". In particular, I would like to be able to specify (within each of those three previous directories) subdirectories with the names of the modules in my application.

    In principle, is it possible ?, How to specify that in my project file (.pro)?
    What other options exist to handle this problem?

    Thank you in advance for any help and/or suggestion.

  • Lifetime Qt Champion


    Can you show your current .pro file ?

  • The file is a bit long. The classes that are called the same are AppDlg and ConfDlg. They belong to the modules "Morph" and "Sgm".

    TARGET   = Cimahis
    TEMPLATE = app
    #Config. Compilador
    QMAKE_CXXFLAGS += -std=c++11
    #Modulos Qt
    QT += webkit
    #Dependencia Externas
    unix {
        INCLUDEPATH += \
            /usr/include/opencv \
        LIBS += \
            -lopencv_core \
            -lopencv_imgproc \
    win32 {
        INCLUDEPATH += \
            3rdparty/tbb/include \
        LIBS += \
            -L$${PWD}/3rdparty/tbb/bin/win -ltbb \
            -L$${PWD}/3rdparty/opencv/bin/win -lopencv_core249d \
                                              -lopencv_imgproc249d \
        #conf. ambiente de ejecucion    =   sys_path_config
        env_config_target.commands  =   set PATH=$(PATH);$${PWD}/3rdparty/tbb/bin/win;$${PWD}/3rdparty/opencv/bin/win
        QMAKE_EXTRA_TARGETS +=  env_config_target
        PRE_TARGETDEPS      +=  sys_path_config
        headers \
        headers/color \
        headers/ctrs \
        headers/morph \
        headers/morph/morphometry \
        headers/texture \
        sources \
        sources/color \
        sources/ctrs \
        sources/morph \
        sources/morph/morphometry \
        sources/texture \
    FORMS += \
        forms/ComboBox.ui \
        forms/Reporte.ui \
        forms/Ayuda.ui \
        forms/visualizarhistograma.ui \
        forms/ventanaumbral.ui \
        forms/elegirFiltros.ui \
        forms/ventanaparametrosfiltro.ui \
        forms/configurarwavelets.ui \
        forms/interfazforma.ui \
        forms/graficoparametros.ui \
        forms/ventanaconfigparametros.ui \
        forms/morph/AppDlg.ui \
        forms/morph/ConfDlg.ui \
        forms/sgm/AppDlg.ui \
    HEADERS += \
        headers/Misc.h \
        headers/Imagen.h \
        headers/interfazSistema.h \
        headers/ComboBox.h \
        headers/Reporte.h \
        headers/Ayuda.h \
        headers/AreaImagen.h \
        headers/qcustomplot.h \
        headers/Cimahis.h \
        headers/color/Color.h \
        headers/color/fabricaObjetos.h \
        headers/color/Histograma.h \
        headers/color/visualizarhistograma.h \
        headers/color/lienzoHistograma.h \
        headers/color/ventanaumbral.h \
        headers/color/elegirFiltros.h \
        headers/color/ventanaparametrosfiltro.h \
        headers/color/filtros.h \
        headers/color/threadFiltro.h \
        headers/color/segmentacion.h \
        headers/ctrs/costos.h \
        headers/ctrs/interfazforma.h \
        headers/ctrs/livewire.h \
        headers/ctrs/qgraphicsviewpersonalizado.h \
        headers/morph/Morph.h \
        headers/morph/AppDlg.h \
        headers/morph/ConfDlg.h \
        headers/morph/morphometry/graficoparametros.h \
        headers/morph/morphometry/morfometria.h \
        headers/morph/morphometry/punto.h \
        headers/morph/morphometry/ventanaconfigparametros.h \
        headers/texture/Wavelet.h \
        headers/texture/ConfigurarWavelets.h \
        headers/sgm/Sgm.h \
        headers/sgm/GfxIt.h \
        headers/sgm/GfxMkr.h \
        headers/sgm/GfxBox.h \
        headers/sgm/GfxCtr.h \
        headers/sgm/ImVw.h \
        headers/sgm/AppDlg.h \
    SOURCES += \
        sources/Misc.cpp \
        sources/Imagen.cpp \
        sources/interfazSistema.cpp \
        sources/ComboBox.cpp \
        sources/Reporte.cpp \
        sources/Ayuda.cpp \
        sources/AreaImagen.cpp \
        sources/qcustomplot.cpp \
        sources/Cimahis.cpp \
        sources/color/Color.cpp \
        sources/color/fabricaObjetos.cpp \
        sources/color/Histograma.cpp \
        sources/color/visualizarhistograma.cpp \
        sources/color/lienzoHistograma.cpp \
        sources/color/ventanaumbral.cpp \
        sources/color/elegirFiltros.cpp \
        sources/color/ventanaparametrosfiltro.cpp \
        sources/color/filtros.cpp \
        sources/color/threadFiltro.cpp \
        sources/color/segmentacion.cpp \
        sources/ctrs/costos.cpp \
        sources/ctrs/interfazforma.cpp \
        sources/ctrs/livewire.cpp \
        sources/ctrs/qgraphicsviewpersonalizado.cpp \
        sources/morph/Morph.cpp \
        sources/morph/AppDlg.cpp \
        sources/morph/ConfDlg.cpp \
        sources/morph/morphometry/graficoparametros.cpp \
        sources/morph/morphometry/morfometria.cpp \
        sources/morph/morphometry/punto.cpp \
        sources/morph/morphometry/ventanaconfigparametros.cpp \
        sources/texture/Wavelet.cpp \
        sources/texture/ConfigurarWavelets.cpp \
        sources/sgm/Sgm.cpp \
        sources/sgm/GfxIt.cpp \
        sources/sgm/GfxMkr.cpp \
        sources/sgm/GfxBox.cpp \
        sources/sgm/GfxCtr.cpp \
        sources/sgm/ImVw.cpp \
        sources/sgm/AppDlg.cpp \
        sources/sgm/ConfDlg.cpp \
    RESOURCES += \
    UI_DIR      = uic
    MOC_DIR     = moc
    OBJECTS_DIR = obj
    CONFIG(  debug, debug|release): DESTDIR = $${OUT_PWD}/debug
    CONFIG(release, debug|release): DESTDIR = $${OUT_PWD}/release
    unix:   OS_TAG = unix
    win32:  OS_TAG = win
    tbblib.path  = $$DESTDIR
    tbblib.files = 3rdparty/tbb/bin/$${OS_TAG}/*
    opencvlib.path  = $$DESTDIR
    opencvlib.files = 3rdparty/opencv/bin/$${OS_TAG}/*
    INSTALLS += tbblib opencvlib

  • Lifetime Qt Champion

    Then use CONFIG += object_parallel_to_source

  • Okay, but

    Can you give me some explanation (or some link to study) about it?

  • Lifetime Qt Champion

  • I continue to have problems compiling. Warnings of type:

    Ignoring old recipe for target 'moc/moc_AppDlg.cpp'
    Overriding recipe for target 'moc/moc_AppDlg.cpp'

    In addition to several related errors: The member functions of Morph::AppDlg are not defined.

  • Lifetime Qt Champion

    Did you re-run qmake or do a clean re-build (i.e. nuke the shadow-build folder) after adding the CONFIG option ?

  • Yes. I deleted the shadow-build folder, and rebuilt the application. I continue to get errors/warnings mentioned above.

    I'm working with Qt 4.8.6 and Qt Creator 2.5.2 (I do not know if that influences).

  • Lifetime Qt Champion

    Oh yes, that influences greatly since object_parallel_to_source is Qt 5 feature.

    Are you locked to that old version of Qt ?

  • Yes, at least temporarily I am required to work with Qt 4.8.6.

    Is there any option to get that same functionality in the Qt version I'm working with?

  • Lifetime Qt Champion

    If you are building Qt yourself, you could try to back port the patch.

  • I'm not building Qt by myself.

    I wonder if there is any way (set of instructions specified in the .pro file, maybe something like what I used under the comment #Instalacion), in Qt 4.8.6, to achieve something similar to the functionality of the object_parallel_to_source option; or something that allows me to have two classes of the same name in my project.

    Can you do such a thing?

  • Lifetime Qt Champion

    You can use object_with_source BUT (and it's a big one) you lose the ability to do out of source builds.

    On a side note, Qt 4.8.6 is not the latest of the Qt 4 series, there's Qt 4.8.7.

  • I will try to use object_with_source.

    On the other hand, I wonder if it will be possible to manually emulate (with instructions in the .pro file, with some script, or something like that) the functionality of the object_parallel_to_source option.

  • Lifetime Qt Champion

    I'd say highly unlikely. Note that you could also try with cmake rather than qmake.

Log in to reply