qmake - loop不分割线

时间:2017-07-20 17:26:03

标签: qt qmake

这可以按预期工作(删除文件):

defineTest(removeFiles) {
    FILES_TO_DEL = $$shell_path($$1) # full paths
    RETURN = $$escape_expand(\n\t)
    for(FILE, FILES_TO_DEL){
        QMAKE_POST_LINK += $$RETURN $$QMAKE_DEL_FILE $$quote($$FILE)
    }
    export(QMAKE_POST_LINK)
}


FILES_TO_DEL = $$DESTDIR/imageformats/qicns.dll \
               $$DESTDIR/imageformats/qico.dll \
               $$DESTDIR/imageformats/qtga.dll \
               $$DESTDIR/imageformats/qtiff.dll \
               $$DESTDIR/imageformats/qwbmp.dll \
               $$DESTDIR/imageformats/qwebp.dll
removeFiles($$FILES_TO_DEL)

但更好的方法是不删除任何东西:

defineTest(removeFilesInDir) {
    PATH_TO_DEL = $$shell_path($$1)
    FILES_TO_DEL = $$shell_path($$2)
    message($$PATH_TO_DEL)
    message($$FILES_TO_DEL)
    RETURN = $$escape_expand(\n\t)
    for(FILE, FILES_TO_DEL){
        message($$FILE)
        QMAKE_POST_LINK += $$RETURN $$QMAKE_DEL_FILE $$quote($${PATH_TO_DEL}$${FILE})
    }
    export(QMAKE_POST_LINK)
}


FDIR = $$DESTDIR/imageformats/
FFILES = qicns.dll qico.dll qtga.dll qtiff.dll qwbmp.dll qwebp.dll
removeFilesInDir($${FDIR}, $${FFILES})

message($$PATH_TO_DEL)显示正确的路径,
message($$FILES_TO_DEL)显示"qicns.dll qico.dll qtga.dll qtiff.dll qwbmp.dll qwebp.dll"(正如预期的那样),
message($$FILE)显示相同的"qicns.dll qico.dll qtga.dll qtiff.dll qwbmp.dll qwebp.dll"(仅限1个)。

为什么removeFilesInDir中的循环不会像removeFiles中那样分割线?如何修复removeFilesInDir

Windows,Qt 5.9,QtCreator,qmake at .pro和.pri文件。

1 个答案:

答案 0 :(得分:0)

它的作品。我从$$shell_path()删除了FILENAMES

# Remove some files from directory (directory_path and file_names)
defineTest(removeFilesInDir) {
    PATH = $$shell_path($${1}) # full path to directory
    FILENAMES = $${2}          # filenames inside directory for remove
    RETURN = $$escape_expand(\n\t)
    for(FILENAME, FILENAMES){
        QMAKE_POST_LINK += $$RETURN $$QMAKE_DEL_FILE $$quote($${PATH}$${FILENAME})
    }
    export(QMAKE_POST_LINK)
}

来自doc.qt

  

<强> shell_path(路径)
  将路径中的所有目录分隔符转换为   与使用的shell兼容的分隔符   构建项目(即make调用的shell)   工具)。例如,当斜杠转换为反斜杠时   使用Windows shell。

我不知道它为什么会中断。