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

145 阅读1分钟

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

\

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

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


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

\

TEMPLATE = aux
TARGET = audio

RESOURCES += audio.qrc

QML_FILES += $$files(*.qml,true) \
             $$files(*.js,true)

QML_SOUNDS += $$files(sounds/*.mp3,true) \
             $$files(sounds/*.wav,true)
CONF_FILES +=  audio.apparmor \
               audio.desktop \
               audio.png
OTHER_FILES += $${CONF_FILES} \
               $${QML_FILES}
#specify where the qml/js files are installed to
qml_files.path = /audio
qml_files.files += $${QML_FILES}
qm_sounds.path = /audio/sounds
qm_sounds.files += $${QML_SOUNDS}
#specify where the config files are installed to
config_files.path = /audio
config_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/sounds
qm_sounds.files += $${QML_SOUNDS}

\

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

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

\

TEMPLATE = aux
TARGET = audio

#SUBDIRS += sounds

RESOURCES += audio.qrc

QML_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.png

OTHER_FILES += $${CONF_FILES} \
               $${QML_FILES}

#specify where the qml/js files are installed to
qml_files.path = /audio
qml_files.files += $${QML_FILES}

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

#specify where the config files are installed to
config_files.path = /audio
config_files.files += $${CONF_FILES}

INSTALLS+=config_files 

\

phablet@ubuntu-phablet:/opt/click.ubuntu.com/audio.liu-xiao-guo/current/audio$ ls
total 64
drwxrwxr-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.qml
drwxrwxr-x 2 clickpkg clickpkg  4096 Mar 31 15:31 sounds

\

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

整个项目的源码:github.com/liu-xiao-gu…

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

\

\

\

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

\