Qt on Android: resource file system qrc and assets, androidqrc
When using Qt for Android development, sometimes our application carries some resource files, such as png and jpg, or some configuration files, such as xml, where are these files stored?
There are two methods:
Let's take a look.
The Qt Resource System
Qrc and Qt resource file systems are easy to use. See the figure:
Figure 1 qrc
Files you put in qrc, such as copy.png, will be compiled into the exe file (the Android Application is libapplication. so ). When you run an application, these resources are also loaded into the memory. If your resources are large, this is a problem.
On the Android platform, you have another option.
Android assets
There is an assets Directory In the Android project directory. The files in this directory will not be packaged into the APK. When the APK is installed on the Android system, the assets will not be installed in the application directory, it is still in APK, but the application can access resources in this folder!
Qt uses this mechanism to implement the assets Virtual File System. Common QFile, QPixmap, and QImage can all access files in assets through "assets.
With the assets Virtual File System, your resource files will not be loaded to the memory when the program starts, saving resources.
Look at a picture:
Figure 2 assets
How can I store resource files? Put it in the android/assets folder under the Qt project directory. 3:
Figure 3 use the directory structure of assets
As long as you put it in this way, the files in assets will be packaged into the APK during Qt compilation, and then they can be accessed in the C ++ code.
Android example using assets
Create a project for Android by referring to Qt on Android: full process of Hello World.
Create AndroidManifest. xml and place a beauty.jpg file in the android/assets Directory. Delete Widgets. h and widgets. cpp of the project. Modify main. cpp as follows:
#include <QApplication>#include <QLabel>#include <QPixmap>int main(int argc, char *argv[]){ QApplication a(argc, argv); QLabel label; QPixmap pixmap("assets:/beauty.jpg"); label.setPixmap(pixmap); label.show(); return a.exec();}
Compile and run. You can see Figure 4:
Figure 4 Qt on Android example using assets
OK. The end is now.
Let's review the Qt on Android series:
Qt on Android: full process of Hello World
Introduction to Qt 5.2 for Android development in Windows
Analysis of the deployment process of Qt for Android
Qt on Android: Output Qt debugging information to logcat.
Qt on Android: Qt 5.3.0 released. Improvements for Android
Qt on Android Episode 1)
Qt on Android Episode 2)
Qt on Android Episode 3)
Qt on Android Episode 4)
Compiling a pure C project using Qt for Android
Compiling Android C language executable programs using Qt for Android in Windows
Qt on Android: Android SDK Installation
Qt on Android: http download and Json Parsing
Set the app name for Qt on Android to Chinese
Qt on Android: Enables full screen display of Qt Widgets and Qt Quick apps
Qt on Android: how to adapt to different screen sizes
Qt on Android: Use JNI and third-party jar packages
Introduction to Qt on Android core programming