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:
qMake generates warnings and compilation fails:
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