3

My app uses 2 classes inheriting from QObject. They have the same name (Communication) but are in different namespaces ("SGBAPI" and "ParamsAPI"). Each is declared in a single file, same name ("communication.h" and "communication.cpp") but different directory("SGB" and "Params"). See screenshot:

enter image description here

qMake generates warnings and compilation fails:

enter image description here

After looking a the makefile, I found out that it generates the same communication.o file for both communication.cpp files.

What can I do to solve this problem? Of course I can rename the source files but they are autogenerated so I prefer another solution if there is one.

Update 1:

.pro file:

QT       += core gui serialport network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = sgbTest
TEMPLATE = app

# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

CONFIG += c++11

SOURCES += \
        main.cpp \
        mainwindow.cpp \
    sgb.cpp

SOURCES += $$files(autogenerated/Params/*.cpp, true) $$files(autogenerated/SGB/*.cpp, true) $$files(lib/*.cpp, true)

HEADERS += \
        mainwindow.h \
    compilationdefines.h \
    sgb.h

HEADERS += $$files(autogenerated/Params/*.h, true) $$files(autogenerated/SGB/*.h, true) $$files(lib/*.h, true)

FORMS += \
        mainwindow.ui \
        lib/com/dlgconnection.ui


# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

Update 2:

Based on p-a-o-l-o answer, I tried using

CONFIG += object_parallel_to_source

It works if the class does not inherits from QObject. If the class inherits from QObject, Qt still generates all the moc_*.cpp files in the compilation's root directory and still does not compile.

Update 3:

Hum, looks like a bug https://bugreports.qt.io/browse/QTBUG-70874

Julien
  • 846
  • 1
  • 7
  • 19
  • How does your `.pro` file look. Depending on how you integrate those files, there might be a workaround to that issue – Felix Jan 29 '19 at 11:01
  • Added in the question. Thanks. – Julien Jan 29 '19 at 11:15
  • Possible duplicate of [Why does qmake put all object (.o) files to one directory?](https://stackoverflow.com/questions/9450225/why-does-qmake-put-all-object-o-files-to-one-directory) – p-a-o-l-o Jan 29 '19 at 14:35
  • I think the most upvoted answer in the above mentioned duplicate should solve the issue. – p-a-o-l-o Jan 29 '19 at 14:35
  • @p-a-o-l-o , unfortunately, it does not work if the class inherits from QObject. I added the reason to the original post. – Julien Jan 29 '19 at 15:20
  • One workaround could be to create a seperate static library for each of the generated folders and link them to the application. – Felix Jan 29 '19 at 16:18
  • Yes, why not !. – Julien Jan 30 '19 at 15:50

0 Answers0