分享

qtcreater中工程文件的模块化管理(.pro文件和.pri文件的创建和管理)

 wuxinit_ 2024-05-14 发布于湖北

.pro

1、创建一个.pro文件

例如:在home文件夹下创建一个home.pro,然后用qtcreater打开

 2、将level_1的工程文件目录转移到home文件目录下

 3、在home.pro添加如下语句

  1. TEMPLATE = subdirs
  2. SUBDIRS += level_1

工程管理界面变成如下所示

 

.pri

1、在level_1目录下添加level_2目录,并在level_2目录下创建level_2.pri文件

 2、在level_1.pro添加如下语句

  1. include($$PWD/level_2/level_2.pri)
  2. INCLUDEPATH += $$PWD/level_2

 工程管理界面变成如下所示

 3、最后在pri文件里面添加各种库、资源文件和配置了

  1. QT += core
  2. QT += gui-private
  3. # TODO: Define your C++ version. c++14, c++17, etc.
  4. CONFIG += c++11
  5. # The following define makes your compiler emit warnings if you use
  6. # any feature of Qt which has been marked as deprecated (the exact warnings
  7. # depend on your compiler). Please consult the documentation of the
  8. # deprecated API in order to know how to port your code away from it.
  9. DEFINES += QT_DEPRECATED_WARNINGS
  10. # You can also make your code fail to compile if you use deprecated APIs.
  11. # In order to do so, uncomment the following line.
  12. # You can also select to disable deprecated APIs only up to a certain version of Qt.
  13. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
  14. isEmpty(level_2_PARENTPATH) {
  15. message( 'level_2_PARENTPATH is empty. use default value.' )
  16. level_2_PARENTPATH = $$PWD/../
  17. } else {
  18. message( 'level_2_PARENTPATH is not empty.' )
  19. message( $${level_2_PARENTPATH} )
  20. }
  21. INCLUDEPATH += $$PWD
  22. INCLUDEPATH += $${level_2_PARENTPATH}
  23. INCLUDEPATH += $${level_2_HEADERPATH}
  24. HEADERS += \
  25. $${level_2_HEADERPATH}temp.h \
  26. SOURCES += \
  27. $${level_2_HEADERPATH}temp.cpp \
  28. win32-g++ {
  29. message("compiling for windows g++. mingw or msys or cygwin.")
  30. INCLUDEPATH += $${level_2_HEADERPATH}win32-gcc
  31. CONFIG(debug, debug|release) {
  32. } else {
  33. }
  34. }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多