Please nominate your Qt Champions for 2021!

Setting and accessing custom files in android (C++/Qt)

  • Hey all!

    I've been having a problem adding custom files to my android project. It is in full C++ and I am using Qt Creator 3.1.2 to deploy it to my android phone, I am able to have Qt copy over my custom assets over to the assets folder in the android build, however my C++ code uses a macro I make in Qmake called PACKAGE_DIRECTORY and the problem is I do not know what to set that path to when it gets deployed onto the app. Is there any C++ code to access files like this? or Qt to find a directory?

    Here is my code to copy over the files:

    android {
    addon.files = $$PWD/../../../packages/Numbers.pkgdef packages
    addon.path = $$[PWD]/assets/packages
    INSTALLS += addon

    and my variable currently:

    PACKAGE_DIRECTORY = /assets/packages/

    Thanks in advance for the help!

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, the assets are support in Qt through a virtual filesystem. You should be able to access your files using the assets:/ prefix.

    Hope it helps

  • hmm it seems to not work when I try to use that prefix to set my environment variable


    am I doing something wrong with it?

  • Lifetime Qt Champion

    Not for your environment variable. Create the assets normally and then you can access them in Qt using this prefix.

    More about it "here":

Log in to reply