Qt on ANDROID:QRC and assets

Source: Internet
Author: User

When using Qt to develop an app for Android, sometimes our app carries some resource files, such as PNG, JPG, and possibly some configuration files, such as XML, where are these files placed?

There are two ways of doing this:

    1. Qrc
    2. Assets

Let's take a look at each other.

The Qt Resource System

QRC, Qt resource file system, very useful oh. Look at a picture:


Figure 1 QRC

Files you put in the QRC, such as Copy.png, will be compiled into an EXE file (Android app is libapplication.so). These resources are also loaded into memory when you run the app. If you have a large resource, this is a problem.

If you're on an Android platform, you have another option.

Android's assets

Android Project directory has a assets directory, the files placed in the directory will be packaged into the APK, apk in the Android system installation, assets will not be installed in the app directory, note that it is still in the APK, but the app can access the resources in this folder !

Qt uses this mechanism, realizes the assets virtual file system, our common QFile, Qpixmap, qimage, etc., all can pass "assets:/" The way to access the files within the assets.

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

Look at a diagram:


Figure 2 Assets

How do you put that resource file? It's simple, just put it in the Android/assets folder in the Qt project directory. 3:


Figure 3 directory structure using the assets

As long as you do this, Qt compiles the files in the assets into the APK, and then it can be accessed within the C + + code.

Android samples using assets

Refer to the Qt on Android: text-to-detail Hello World process to build a project for Android.

Create a androidmanifest.xml and then devolve a beauty.jpg in the Android/assets directory. Delete the widget.h and widget.cpp of the project. Modify the 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, and 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: text-to-detail Hello world whole process
  • Introduction to the development of Qt 5.2 for Android under Windows
  • Qt for Android deployment process Analysis
  • QT on Android: output qt Debug information to Logcat
  • Qt on ANDROID:QT 5.3.0 released for Android improvement instructions
  • 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 compiled pure C project
  • Windows under Qt for Android compiled Android C language executable program
  • Qt on Android:android SDK installation
  • Qt on android:http download and JSON parsing
  • Qt on Android Settings app is named Chinese
  • QT on Android: let Qt Widgets and QT Quick apply full screen display
  • Qt on Android: How to adapt to different screen sizes
  • Qt on Android: Using JNI with third-party jar packages
  • Introduction to "Qt on Android Core programming"
  • Qt on ANDROID:QRC and assets

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.