Important: Please read the Qt Code of Conduct -

Files from Assetsfolder in C++

  • Hi All,
    I think I don't get the point with the assets folder. I want to deploy some files with the assets folder (not in a qrc).
    Within qml I can perfectly access them with:

    Qt.resolvedUrl("../../assets/" + fileName)

    But I can't get them within C++:

    QFile file("assets:/" + fileName);

    From what I have read the "assets:/" works like the "file:/" prefix but I always get fileExists false in C++. But its there because from qml I can access it.....

    Any hints?

  • @patrikd
    What platform are you on? I read that QFile("assets:/") is Android only, but you don't say.

    Otherwise you may need to state your Qt version, e.g.

  • I'm currently trying it on Android and Win-Desktop. Both not working. Qt 5.13.2.

  • Moderators

    just to clarify it wont work on Windows, only on Android (device and emulator).
    Any chance you simply incorrectly assume that those 2 paths point to the same file?!
    Simply traverse the "assets:/" root folder and check it's contents.

  • @raven-worx
    Hi Raven,

    so if I make:

        QDir dir("assets:"); //with / and without /
        QFileInfoList list = dir.entryInfoList();
        for (int i = 0; i < list.size(); ++i) {
            QFileInfo fileInfo =;
            qDebug() << fileInfo.fileName();

    Nothing is printed out.
    Is there a C++ equivalent for:

    Qt.resolvedUrl("../../assets/" + fileName)

    ? Because this one works like charm on Android, iOS, Windows and MacOs.
    In my .pro file I have:

    assetsFolder.source = assets
    DEPLOYMENTFOLDERS += assetsFolder


  • Moderators

    @patrikd said in Files from Assetsfolder in C++:

    Because this one works like charm on Android, iOS, Windows and MacOs.

    assets: is just for accessing Android's assets resources.

    Qt.resolvedUrl() loads relative urls from it's loading url context.
    I don't know your exact desired folder structure.
    Are you actually trying to read files from the filesystem?
    How are you loading your inital QML root file actually?

  • @raven-worx
    Entry point:


    With the setting in the pro file I get the asset folder deployed on all plattforms. So the folder is in a way accesible. But
    I don't get it in C++.

    Here the folders:

Log in to reply