How to use DEPLOYMENTFOLDERS directive in Qt Widget based application

不羁的心 提交于 2021-01-22 07:05:55

问题


When I use the Qt Creator to create a Qt Quick / QML project it adds DEPLOYMENTFOLDERS to the .pro file. I can use this directive to get some folders/files copied to the build directory upon building (compilation) of the application.

How can I use this in a simple Qt Widget based application?

Qt Creator doesn't add it for a simple Qt project and when I manually do it, it's not working.

This is my project file:

folder_01.source = sounds
#folder_01.target =
DEPLOYMENTFOLDERS += folder_01

QT += core gui widgets
TARGET = myApp
TEMPLATE = app
SOURCES += main.cpp

I tried "/sounds" and "sounds/*" and thinks like that. But nothing works. What am I missing here?


回答1:


I was researching this and stumbled on this unanswered question.

Basically I do advocate using the resource system but when you're doing rapid UI development (qml) waiting for the Resource file to compile can be an irritation so I wanted to simply copy this files over.

What is confusing here is the source/target mean slightly different things. The best way to describe it is copy this -> this root as opposed to copy this -> here

My build simply wants my resources "raw" on the path so I am copying folder->/ Here's an example of the project file I have:

folder_qml.source = qml
folder_qml.target = /
folder_js.source = js
folder_js.target = /
folder_img.source = img
folder_img.target = /
DEPLOYMENTFOLDERS += folder_qml folder_js folder_img

When you build you can verify the output:

10:41:57: Starting: "C:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" 
C:/Qt/Qt5.2.1/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Development/Subversion/MyBuild-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
Copying application data... 
60 File(s) copied
12 File(s) copied
6 File(s) copied
mingw32-make[1]: Leaving directory 'C:/Development/Subversion/MyBuild-Desktop_Qt_5_2_1_MinGW_32bit-Debug'
Copying application data... 
60 File(s) copied
12 File(s) copied
6 File(s) copied
10:41:58: The process "C:\Qt\Qt5.2.1\Tools\mingw48_32\bin\mingw32-make.exe" exited normally.

The resulting build looks like:

/Build dir/
  + release
  + debug
  + qml
  + js
  + img
  Makefile.Release
  Makefile.Debug
  Makefile

I hope this helps answer your question. I didn't find any documentation on it so I just played with it until it worked. (It is very helpful with mock-data for tests).




回答2:


I've just been through the docs (for 4.8 & 5.x) and there's no documentation for that variable in the qmake section so it looks like it's purely for qml. If you're trying to compile resources in the usual way is to use a qrc file to specify the resources, not sure why Qt decided to change over to DEPLOYMENTFOLDERS for qml only.



来源:https://stackoverflow.com/questions/18441129/how-to-use-deploymentfolders-directive-in-qt-widget-based-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!