简体   繁体   中英

How can i add a custom build step in Qt Creator project wizard?

I used to have a project templates, when i code in Visual Studio, but now i have to use Qt Creator and find out it has something very similar, which called "Project Wizard". I need to have text file, which will be copied to build folder, and solved it by adding a new build step, but i can't understand how to add a new build step in project wizard file. So, i took a "plaincpp" project wizard to base on, and it hasn't got any cmake files to change. Also i found, what Qt Creator stores build steps in *.pro.user file.

您可以将QMAKE_POST_LINK += /path/to/some/script/or/binaryyour_project.pro文件,并编写一个简单的bash脚本或任何您想执行的脚本来复制文件。

As stated by @0x35 you can use the QMAKE_POST_LINK += <arguments> by putting it anywhere in the .pro file. (On windows this method sometimes requires a clean first).

Other arguments to consider as implied by the comments of @hoholok (and some research):

  • The current build directory is found using $$OUT_PWD and
  • the source directory using $$PWD
  • The .pro file directory $$_PRO_FILE_PWD_
  • To go up from the directory using these arguments use ../ ex: $${OUT_PWD}/../otherFolder/

For the Windows user the directories given above use forward slashes. This in turn causes the builds to fail. The forward slashes should be turned into two backslashes. ex (works in solution .pro file):

Directory_to_Use = some_Directory #initialization for linux directory
PWD_WIN = $${OUT_PWD} #Set PWD_WIN to output directory
win32 # this code only executes on a windows machine
{
    Directory_to_Use = C:\\_Dev\\Qt\5.9.1\\mingw53_32\\bin #change linux path to the windows path
    PWD_WIN ~= s,/,\\,g #change all forward slashes into double backslashes
}
QMAKE_POST_LINK += COPY $$Directory_to_Use\\Qt5* $$PWD_WIN\\debug   #command that works on both linux and windows

This code example snippet copies all the Qt dlls from my Qt installed directory into the project build directory.

If more than one command needs to be executed post build just add another QMAKE_POST_LINK += <arguments> or even put it in a for loop as here: for loop in .pro file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM