Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Files from Assetsfolder in C++
Forum Update on Monday, May 27th 2025

Files from Assetsfolder in C++

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 953 Views
  • 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.
  • patrikdP Offline
    patrikdP Offline
    patrikd
    wrote on last edited by
    #1

    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?
    Best,
    Patrik

    JonBJ 1 Reply Last reply
    0
    • patrikdP patrikd

      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?
      Best,
      Patrik

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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. https://stackoverflow.com/questions/48211797/copy-file-from-assets-to-permanent-location-qt-android.

      1 Reply Last reply
      0
      • patrikdP Offline
        patrikdP Offline
        patrikd
        wrote on last edited by patrikd
        #3

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

        raven-worxR 1 Reply Last reply
        0
        • patrikdP patrikd

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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @patrikd
          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.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          patrikdP 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @patrikd
            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.

            patrikdP Offline
            patrikdP Offline
            patrikd
            wrote on last edited by
            #5

            @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 = list.at(i);
                    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
            

            Thx,
            Patrik

            raven-worxR 1 Reply Last reply
            0
            • patrikdP patrikd

              @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 = list.at(i);
                      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
              

              Thx,
              Patrik

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

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

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

              What?!
              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?

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              patrikdP 1 Reply Last reply
              0
              • raven-worxR raven-worx

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

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

                What?!
                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?

                patrikdP Offline
                patrikdP Offline
                patrikd
                wrote on last edited by patrikd
                #7

                @raven-worx
                Entry point:

                    felgo.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
                    engine.load(QUrl(felgo.mainQmlFileName()));
                

                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:
                folders.PNG
                Thx,
                Patrik

                1 Reply Last reply
                0

                • Login

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