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.
  • P Offline
    P Offline
    patrikd
    wrote on 4 Dec 2020, 12:00 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

    J 1 Reply Last reply 4 Dec 2020, 12:08
    0
    • P patrikd
      4 Dec 2020, 12:00

      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

      J Offline
      J Offline
      JonB
      wrote on 4 Dec 2020, 12:08 last edited by JonB 12 Apr 2020, 12:10
      #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
      • P Offline
        P Offline
        patrikd
        wrote on 4 Dec 2020, 12:10 last edited by patrikd 12 Apr 2020, 12:11
        #3

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

        R 1 Reply Last reply 4 Dec 2020, 12:50
        0
        • P patrikd
          4 Dec 2020, 12:10

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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 4 Dec 2020, 12:50 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

          P 1 Reply Last reply 4 Dec 2020, 13:27
          0
          • R raven-worx
            4 Dec 2020, 12:50

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

            P Offline
            P Offline
            patrikd
            wrote on 4 Dec 2020, 13:27 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

            R 1 Reply Last reply 4 Dec 2020, 13:34
            0
            • P patrikd
              4 Dec 2020, 13:27

              @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

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 4 Dec 2020, 13:34 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

              P 1 Reply Last reply 4 Dec 2020, 13:47
              0
              • R raven-worx
                4 Dec 2020, 13:34

                @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?

                P Offline
                P Offline
                patrikd
                wrote on 4 Dec 2020, 13:47 last edited by patrikd 12 Apr 2020, 13:59
                #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

                1/7

                4 Dec 2020, 12:00

                • Login

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