Qt:覆盖/忽略相同名称但名称空间不同的2个类的配方和多重定义

时间:2019-01-29 09:30:51

标签: c++ qt makefile namespaces

我的应用程序使用2个从QObject继承的类。它们具有相同的名称(通信),但位于不同的名称空间(“ SGBAPI”和“ ParamsAPI”)中。每个文件都在一个相同名称(“ communication.h”和“ communication.cpp”)但目录(“ SGB”和“ Params”)不同的文件中声明。查看屏幕截图:

enter image description here

qMake生成警告,编译失败:

enter image description here

查看makefile文件后,我发现它为两个communication.cpp文件生成相同的communication.o文件。

我该怎么做才能解决此问题?当然,我可以重命名源文件,但是它们是自动生成的,因此,如果有的话,我更喜欢另一种解决方案。

更新1:

.pro文件:

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

更新2:

基于p-a-o-l-o答案,我尝试使用

CONFIG += object_parallel_to_source

如果该类不继承自QObject,则它起作用。 如果该类继承自QObject,则Qt仍会在编译的根目录中生成所有moc _ *。cpp文件,并且仍不会编译。

更新3:

哼,看起来像个错误https://bugreports.qt.io/browse/QTBUG-70874

0 个答案:

没有答案