QT pro pri

作者: c之气三段 | 来源:发表于2021-06-22 21:34 被阅读0次

    QT分模块,会有单独目录需要自己配置引用
    pro

    #-------------------------------------------------
    #
    # Project created by QtCreator 2021-06-22T11:35:00
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = AA
    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
    CONFIG(debug, debug|release) {
            DESTDIR = $$PWD/../bin_d
        TARGET = AA
        CONFIG += console
        CONFIG -= qml_debug
    } else {
            DESTDIR = $$PWD/../bin_r
        TARGET = AA
        CONFIG -= console
    #    DEFINES += QT_NO_DEBUG_OUTPUT
    }
    
    #组件头文件包含目录
    INCLUDEPATH += $$_PRO_FILE_PWD_
    #自主模块包含
    include($$PWD/GUI/GUI.pri)
    
    SOURCES += \
            main.cpp
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    GUI目录
    pri

    INCLUDEPATH += $$PWD
    include($$PWD/MainWindow/MainWindow.pri)
    include($$PWD/TreeModel/TreeModel.pri)
    
    

    MainWindow目录
    pri配置头文件

    FORMS += \
             $$PWD/MainWindow.ui \
             $$PWD/ShowWiget.ui
    
    HEADERS += \
             $$PWD/MainWindow.h \ 
             $$PWD/ShowWiget.h
            
    SOURCES += \
             $$PWD/MainWindow.cpp \ 
             $$PWD/ShowWiget.cpp
    
    
    

    多子工程pro

    好处可以单独构建每个模块

    父pro

    TEMPLATE = subdirs
    
    SUBDIRS =\
          $$PWD/VTKTest/FileIO/FileIO.pro \
          $$PWD/VTKTest/GUI/GUI.pro
    
    CONFIG += ordered
    
    

    入口pro

    #-------------------------------------------------
    #
    # Project created by QtCreator 2021-06-22T11:35:00
    #
    #-------------------------------------------------
    
    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = VTKTest
    TEMPLATE = app
    
    CONFIG += c++11
    # 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(debug, debug|release) {
        DESTDIR = $$PWD/../../../bin_d
        CONFIG += console
        CONFIG -= qml_debug
    } else {
        DESTDIR = $$PWD/../../../bin_r
        CONFIG -= console
    }
    
    
    INCLUDEPATH += $$PWD
    
    include($$PWD/MainWindow/MainWindow.pri)
    include($$PWD/VTK/VTK.pri)
    include($$PWD/../FileIO/FileIO.pri)
    HEADERS += \
    
    SOURCES += \
            $$PWD/main.cpp
    
    RESOURCES += \
        $$PWD/../../../res/res.qrc
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    FileIO.pro 模块pro/子pro 也是发布第三方库的方法
    方法一:该方法只是简单使用,无法实时更新到指定位置

    #-------------------------------------------------
    #
    # Project created by QtCreator 2021-06-22T11:35:00
    #
    #-------------------------------------------------
    
    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TEMPLATE = lib
    # 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
    #输出dll/lib
    #CONFIG -= staticlib
    #CONFIG += dll
    
    CONFIG += staticlib
    CONFIG -= shared
    
    #编译输出lib/dll
    CONFIG(debug, debug|release) {
       TARGET = FileIO_d
       target.path = $$PWD/Lib/lib_d
    }
    else {
       TARGET = FileIO
       target.path = $$PWD/Lib/lib_r
    }
    INSTALLS += target
    #拷贝dll到指定位置
    CONFIG(debug, debug|release) {
       dllTarget.files += $$PWD/Lib/lib_d/FileIO_d.dll
       dllTarget.path = $$PWD/../../../bin_d
    }
    else {
       dllTarget.files += $$PWD/Lib/lib_r/FileIO.dll
       dllTarget.path = $$PWD/../../../bin_r
    }
    INSTALLS += dllTarget
    
    #自主模块包含
    include($$PWD/CGNSIO/CGNSIO.pri)
    
    DISTFILES += \
        FileIO.pri
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    

    FileIO.pri模块/子pri被主模块引用和pro同级

    #如果模块中引用了外部库写在此处,模块中也要写明引用的头文件路径不然会报错
    INCLUDEPATH += $$PWD/../../../External_Lib/CGNS_4.2.0/HDF5_1.12.0/include \
                   $$PWD/CGNSIO
    Debug: {
        LIBS += -L$$PWD/../../../External_Lib/CGNS_4.2.0/HDF5_1.12.0/Debug/lib \
                -L$$PWD/../../../External_Lib/CGNS_4.2.0/HDF5_1.12.0/Debug/lib/pkgconfig
    
        LIBS += -lcgns \
                -llibhdf5_cpp_D \
                -llibhdf5_D \
                -llibhdf5_hl_cpp_D \
                -llibhdf5_hl_D \
                -llibhdf5_tools_D
    }
    Release:{
        LIBS += -L$$PWD/../../../External_Lib/CGNS_4.2.0/HDF5_1.12.0/Release/lib \
                -L$$PWD/../../../ernal_Lib/CGNS_4.2.0/HDF5_1.12.0/Release/lib/pkgconfig
    
        LIBS += -lcgns \
                -llibhdf5 \
                -llibhdf5_cpp \
                -llibhdf5_hl \
                -llibhdf5_hl_cpp \
                -llibhdf5_tools
    }
    
    Debug: {
        LIBS += -L$$PWD/Lib/lib_d
        LIBS += -lFileIO_d
    }
    Release:{
        LIBS += -L$$PWD/Lib/release
        LIBS += -lFileIO
    }
    
    
    image.png

    方法二:推荐使用,每次代码更改就能更新到指定位置

    #-------------------------------------------------
    #
    # Project created by QtCreator 2021-06-22T11:35:00
    #
    #-------------------------------------------------
    
    TEMPLATE = lib
    
    # 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
    #输出dll lib
    CONFIG -= staticlib
    CONFIG += dll
    
    #编译输出lib/dll
    CONFIG(debug, debug|release) {
       TARGET = EncryptionStr_d
       DESTDIR = $$PWD/Lib/lib_d
    }
    else {
       TARGET = EncryptionStr
    DESTDIR = $$PWD/Lib/lib_r
    }
    
    #拷贝dll到指定位置
    
    CONFIG(debug, debug|release) {
        copy_lib.sources = $${DESTDIR}/EncryptionStr_d.dll
        copy_lib.sources = $$replace(copy_lib.sources, /, \\)
        copy_lib.target = $$PWD/../../bin_d
        copy_lib.target = $$replace(copy_lib.target, /, \\)
        copy_lib.commands = xcopy $$copy_lib.sources $$copy_lib.target /E/Y
        QMAKE_POST_LINK+= $$copy_lib.commands
    }
    else {
        copy_lib.sources = $${DESTDIR}/EncryptionStr.dll
        copy_lib.sources = $$replace(copy_lib.sources, /, \\)
        copy_lib.target = $$PWD/../../bin_r
        copy_lib.target = $$replace(copy_lib.target, /, \\)
        copy_lib.commands = xcopy $$copy_lib.sources $$copy_lib.target /E/Y
        QMAKE_POST_LINK+= $$copy_lib.commands
    }
    
    HEADERS += \
        EncryptionStr.h \
        Regulation.h
    
    SOURCES += \
        EncryptionStr.cpp \
        Regulation.cpp
    
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    引用时

    INCLUDEPATH += \
    $$PWD/../../EncryptionStr
    
    Debug: {
        LIBS += -L$$PWD/../../EncryptionStr/Lib/lib_d
    
        LIBS += -llibEncryptionStr_d
    }
    Release:{
        LIBS += -L$$PWD/../../EncryptionStr/Lib/lib_r
    
        LIBS += -llibEncryptionStr
    }
    

    相关文章

      网友评论

        本文标题:QT pro pri

        本文链接:https://www.haomeiwen.com/subject/tzgmyltx.html