• qmake 时复制文件(自动在编译前做一些操作,且写在.pro文件里)


    有时在编译前需要准备一些文件,例如修改了 QtCreator 的编译输出目录: Build & Run > Default build directory,使用 Promote 后需要在编译前把相应 Widget 的头文件复制到 .o 文件所在的目录,这时就可以在 .pro 文件中使用复制文件的命令(其实就是执行系统命令),让 qmake 执行这些命令来复制文件,而不是手动的复制需要的文件。

    可以使用 qmake 时能执行系统的命令的特性来做很多事情,不只是复制文件。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    QT += core gui sql xml
     
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
     
    TARGET = Schedule
    TEMPLATE = app
    CONFIG -=app_bundle
     
    # Output directory
    CONFIG(debug, debug|release) {
    compiled = debug
    }
    CONFIG(release, debug|release) {
    compiled = release
    }
     
    # All temporay files are all put in the directory $$compiled
    DESTDIR = bin
    OBJECTS_DIR = $$compiled
    MOC_DIR = $$compiled
    RCC_DIR = $$compiled
    UI_DIR = $$compiled
     
    # Copy promotion required headers to build directory
    win32 {
    COPY_DEST = $$replace(OUT_PWD, /, \)
    system("copy gui\ClassWidget.h $$COPY_DEST\$$compiled\ClassWidget.h")
    system("copy gui\CourseWidget.h $$COPY_DEST\$$compiled\CourseWidget.h")
    system("copy gui\TeacherWidget.h $$COPY_DEST\$$compiled\TeacherWidget.h")
    }
     
    mac {
    system("cp gui/ClassWidget.h $$OUT_PWD/$$compiled/ClassWidget.h")
    system("cp gui/CourseWidget.h $$OUT_PWD/$$compiled/CourseWidget.h")
    system("cp gui/TeacherWidget.h $$OUT_PWD/$$compiled/TeacherWidget.h")
    }
     
    SOURCES += main.cpp

    在 .pro 文件里路径分隔符都是 /,但在 Windows 中, / 对于 copy 命令有特殊用途,所以需要把 / 替换为 ,否则复制文件会失败

    http://www.qtdebug.com/qtbook-misc-qmake-copy-file/

  • 相关阅读:
    如何让你的网站排名靠前
    经典ASP代码大集合
    防刷新重复提交、防后退方法
    ASP.NET中数据库数据导入Excel并打印
    制作网页过程中经常要用到的代码
    在ASP.NET中使用Microsoft Word文档
    document对象详解
    用XP做服务器突破iis10人限制
    自动选择网通电信服务器
    PHP笔记——获取文件扩展名
  • 原文地址:https://www.cnblogs.com/findumars/p/5058248.html
Copyright © 2020-2023  润新知