如何把一个目录及其以下的所有文件在qmake项目中打包

来源:互联网 发布:福利狗电视直播软件 编辑:程序博客网 时间:2024/05/16 06:13

在我们许多的项目中,我们需要用到一些资源.这些资源我们想分别放入到自己分别的目录中,比如images, videos, audios或assets.当我们打包我们的qmake应用时,我们需要把这些目录也打入到我们的中,并保证我们的应用所引用的文件保持相应的文件架构(相对文件路径).否则我们的应用不会真确运行.也有很多的web应用,我们希望把所有的文件一起打入到我们的应用中,这样我们可以可以使用WebView来访问.


我们还是拿我们先前的一个例子:

$ git clone https://github.com/liu-xiao-guo/audio

在那个例子中,我们的.pro文件如下:


TEMPLATE = auxTARGET = audioRESOURCES += audio.qrcQML_FILES += $$files(*.qml,true) \             $$files(*.js,true)QML_SOUNDS += $$files(sounds/*.mp3,true) \             $$files(sounds/*.wav,true)CONF_FILES +=  audio.apparmor \               audio.desktop \               audio.pngOTHER_FILES += $${CONF_FILES} \               $${QML_FILES}#specify where the qml/js files are installed toqml_files.path = /audioqml_files.files += $${QML_FILES}qm_sounds.path = /audio/soundsqm_sounds.files += $${QML_SOUNDS}#specify where the config files are installed toconfig_files.path = /audioconfig_files.files += $${CONF_FILES}INSTALLS+=config_files qml_files qm_sounds

在这里我们使用了:

QML_SOUNDS += $$files(sounds/*.mp3,true) \             $$files(sounds/*.wav,true)

qm_sounds.path = /audio/soundsqm_sounds.files += $${QML_SOUNDS}


来把我们的文件打包到我们需要的文件目录中.整个的过程非常麻烦.

在今天的例程中,我们来直接把我们的.pro文件修改为:


TEMPLATE = auxTARGET = audio#SUBDIRS += soundsRESOURCES += audio.qrcQML_FILES += $$files(*.qml,true) \             $$files(*.js,true) \             sounds#QML_SOUNDS += $$files(sounds/*.mp3,true) \#             $$files(sounds/*.wav,true)CONF_FILES +=  audio.apparmor \               audio.desktop \               audio.pngOTHER_FILES += $${CONF_FILES} \               $${QML_FILES}#specify where the qml/js files are installed toqml_files.path = /audioqml_files.files += $${QML_FILES}#qm_sounds.path = /audio/sounds#qm_sounds.files += $${QML_SOUNDS}#specify where the config files are installed toconfig_files.path = /audioconfig_files.files += $${CONF_FILES}INSTALLS+=config_files 

phablet@ubuntu-phablet:/opt/click.ubuntu.com/audio.liu-xiao-guo/current/audio$ lstotal 64drwxrwxr-x 3 clickpkg clickpkg  4096 Mar 31 15:31 .drwxr-xr-x 4 clickpkg clickpkg  4096 Mar 31 15:31 ..-rw-r--r-- 1 clickpkg clickpkg   114 Mar 31 15:31 audio.apparmor-rw-r--r-- 1 clickpkg clickpkg   167 Mar 31 15:31 audio.desktop-rw-r--r-- 1 clickpkg clickpkg 38968 May  7  2015 audio.png-rw-r--r-- 1 clickpkg clickpkg  1291 Aug 23  2015 Main.qmldrwxrwxr-x 2 clickpkg clickpkg  4096 Mar 31 15:31 sounds

在这里,我们只在上面的QML_FILES中加入"sounds"即可.这样整个"sounds"将会整个打包入我们的应用中.

整个项目的源码:https://github.com/liu-xiao-guo/audio_path

如果大家感兴趣的话,大家可以把一个西班牙开发的项目uNav变为一个Qt Creator的项目.我已经帮他做了:




呵呵,这是我家的位置哦!


0 1
原创粉丝点击