QT pro中加入文件拷贝方法_qt pro复制粘贴-CSDN博客
目标:
例如:在release模式下,exe文件生成于:
"G:\test\build\release\shakeSensor.exe"
此时,我希望在生成该exe文件时,
"G:\test\build\test\"
此目录下也可生成该exe文件
可以在.pro文件中执行复制文件命令
相关代码:
cpp
CONFIG(debug, debug|release) {
ROUTDIR = $$PWD/../build/debug
TARGET = shakeSensor_d
} else {
ROUTDIR = $$PWD/../build/release
TARGET = shakeSensor
DEFINES+= QT_NO_DEBUG_OUTPUT
TargetEXE = $$ROUTDIR
TargetEXE = $$replace(TargetEXE, /, \\)
OutputDir = $$PWD/../build/test
OutputDir = $$replace(OutputDir, /, \\)
QMAKE_POST_LINK += copy /Y $$TargetEXE $$OutputDir
}
DESTDIR = $$ROUTDIR
可以看到
ROUTDIR = $$PWD/../build/release
DESTDIR = $$ROUTDIR
ROUTDIR为exe的输出目录,对应"G:\test\build\release\shakeSensor.exe"
TargetEXE = $$ROUTDIR
TargetEXE = $$replace(TargetEXE, /, \\)
OutputDir = $$PWD/../build/test
OutputDir = $$replace(OutputDir, /, \\)
QMAKE_POST_LINK += copy /Y $$TargetEXE $$OutputDir
这部分代码用于复制原始exe到 "G:\test\build\test\"
TargetEXE存储原始exe的路径
OutputDir存储希望得到的新exe的路径
最后:
QMAKE_POST_LINK += copy /Y $$TargetEXE $$OutputDir
这句代码实现:把TargetEXE复制到OutputDir目录下