Qt on Android resource file system qrc and assets

               

When using Qt to develop apps for Android, sometimes our app will carry some resource files, such as png, jpg, etc., or there may be some configuration files, such as xml, etc. Where are these files placed?

There are two ways:

  1. qrc
  2. assets

Let's take a look at each.

the Qt Resource System

Qrc, Qt's resource file system, very easy to use. Look at a picture:


Figure 1 qrc schematic

Files you put in qrc, such as copy.png , will be compiled into the exe file (Android application is libapplication.so ). These resources are also loaded into memory when you run the app. If your resources are large, this is a problem.

If it's on the Android platform, you have another option.

Android assets

There is an assets directory in the Android project directory. The files placed in this directory will be packaged into the APK. The APK will not be installed into the application directory when the Android system is installed. Note that it is still in the APK. But the app can access the resources in this folder!

Qt uses this mechanism to implement the assets virtual file system. Our common QFile, QPixmap, QImage, etc. can access the files in assets through "assets:/".

With the assets virtual file system, your resource files are not loaded into memory at program startup, saving resources.

Look at a picture:


Figure 2 Asset diagram

How to put the resource file? Very simple, just put it in the android/assets folder in the Qt project directory. Figure 3:


Figure 3 Directory structure using assets

As long as you put it in, Qt compiles the files in assets into APKs and then accesses them in C++ code.

Android example using assets

ReferenceQt on Android: Graphical explanation of the whole process of Hello World》Build a project for Android.

Create AndroidManifest.xml and place a beauty.jpg in the android/assets directory. Delete the widget.h and widget.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, run, you can see Figure 4:


Figure 4 Qt on Android example using assets


OK, this is the end.

Review the Qt on Android series:

Qt on Android: Graphical explanation of the whole process of Hello World Getting started with Qt 5.2 for Android development under Windows Qt for Android deployment process analysis Qt on Android: Output Qt debugging information to logcat Qt on Android: Qt 5.3.0 release, improved instructions for Android Qt on Android Episode 1 (translation) Qt on Android Episode 2 (translation) Qt on Android Episode 3 (translation) Qt on Android Episode 4 (translation) Qt for Android compiles pure C project Qt for Android compiles Android C language executable program under Windows Qt on Android: Android SDK installation Qt on Android: http download and Json analysis Qt on Android settings app is called Chinese Qt on Android: Let Qt Widgets and Qt Quick apps display full screen Qt on Android: How to adapt to different screen sizes

 Qt on Android: Using JNI with third-party jar packages

"Qt on Android core programming" introduction


           

Then share the artificial intelligence tutorial of my teacher, God. Zero-based! Easy to understand! Humorous! Also with a yellow paragraph! I hope that you will also join our team of artificial intelligence!this link

Intelligent Recommendation

QT obtain QRC file list

1. Code 2. Effect As shown in the figure, get the file list in this QRC Partial print output...

Android read jar assets in the resource file package

In Android resource files can be placed in assets directory (subdirectories can have) Packing and program together for the jar, the jar package can be referenced only in the other project reference, d...

Android read file resource assets and raw file resource

  res / raw points and assets of the same: 1. Both file folder after packaging will be stored in intact apk package. It will not be compiled into a binary. res / raw assets and differences: 1.res...

[PYQT] use .QRC generation resource file for use

[PYQT] use .QRC generation resource file for use Establish an images.qrc file, save the resource location: 1 2 3 4 5 6 7 8 9 By command, use this qrc file to generate images.py resource files: 1 Use i...

More Recommendation

Dependent 'resource file name .QRC' Does not exist.

Qt Under the error: Dependent 'resource file name .QRC' Does not exist. The reason is not found to find the original file Place the resource file in the folder where the source code is located, then.p...

The .ui file and .qrc file encountered when learning vs2010+qt cannot be opened correctly and the image icon resource loading problem

Premise: Since my work colleagues are joint projects developed in vs2010+qt and under vs, I also have to follow this line of thinking. Most of the online routines are developed under QT Creater. Most ...

Using resource files (2017) Tools in the Qt VS .qrc

QT how to use resource files .qrc Here the record about the time the summary txt file: Step (I use): After this mainly to solve the replacement of the computer, run the .exe file, the picture does not...

C ++ qt opencv cannot read the solution of QRC resource files

In order to avoid different paths on the picture files on different computers, QT introduces the concept of resource files, but when OpenCV reads pictures, the resource file path cannot be recognized....

(Turn) android jni read the FAQ assets of the resource file (with source code)

(turn) Underlying assets directory files are packaged into a apk file, these resources are decompressed when they did not install, use is read directly from the apk. Here in the introduction to how to...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top