Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Load files (databases, audio files, images) to Android Emulator devices internal storage
Qt 6.12 LTS is out! See what's new in the release blog

Load files (databases, audio files, images) to Android Emulator devices internal storage

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DSpUz
    wrote last edited by
    #1

    Dear Qt Devs,

    I create this post because it answers at least 100 topics that are all under a different name in hope that future posts get linked to this one and people contribute to the solution provided here.

    Lets say your app uses a database file. When you build your project on a windows system and the target is set to an android device deploy_button.png

    Unfortunately, the database file(or audio files or whatever), even though you might have it added under the resources in CMAKE file in your project, won't be copied in the internal memory of the target device image ( in this case the AndroidTablet AVD).

    To fix this,

    1. go to the SDK folder path in windows explorer: sdk_location.png
      , and open platform-tools folder which contains the adb.exe executable. While in this folder, type powershell in the address bar to start powershell at this location:
      powershell_command_adb.png

    2. Your emulator needs to be running for the file transfer commands to work, either start it by running your programm, or use Start AVD button from Preferences -> Devices inside of Qt-Creator.

    3. Now in PowerShell, use .\adb.exe shell pm list packages -3 , to list 3rd party installed packages which should list your app name that you can use in next steps: list_packages.png

    4. Since I think one cannot access the app files folder directly you first need to push the files to a temporary location(can also be sd card memory) of the AVD. Use push command .\adb.exe push "C:\Qt_test_projects\example-db" /data/local/tmp/example-db and it will copy the file from your windows folder to the android emulated device: push_file_to_tmp_location.png

    5. copy (alternatively - move) the file inside your app files folder using run-as command option with the previously retrieved package name .\adb.exe shell run-as org.qtproject.example.appsqlmodel cp /data/local/tmp/example-db files/example-db to access it: copy_file.png

    6. Now your file should be in the files folder that is the default path where your main app will look for, you can list the files in this folder using .\adb.exe shell run-as org.qtproject.example.appsqlmodel ls -l files command.:
      files_folder_content.png
      You can also check the working directory name through your main.cpp file and check if that resource exists, for this you need to include <QDebug> ,<QDir> and <QFileInfo> in the main.cpp and then use:

    qDebug() << "Working directory:" << QDir::currentPath();
    qDebug() << "Database path:"<< QFileInfo("./example-db").absoluteFilePath();
    qDebug() << "Database exists:" << QFileInfo::exists("./example-db");
    qDebug() << "Database size:" << QFileInfo("./example-db").size();
    

    this will give you some info in the application output window when you run it:
    application_output_debug_messages.png

    1. Enjoy that your App in your Android Emulator doesn't crash and can load the resources it should be loading PayPal me some money lol.

    Cheers

    https://github.com/DSpUz

    1 Reply Last reply
    0
    • D DSpUz marked this topic as a regular topic

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt
    • Unsolved