Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Grouping files into a container file / VFS / Access from QML
QtWS25 Last Chance

Grouping files into a container file / VFS / Access from QML

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 4 Posters 4.5k 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.
  • C Offline
    C Offline
    conny
    wrote on last edited by
    #1

    Hi,

    I have hundreds of files that I want to deploy with my application. For several reasons I'd like to put all of them into one file and then access them using QUrl from QML. Basically I would like to use the Qt resource system, but I can't. It's too much data and my machine cannot handle the compilation.

    So I thought about putting all those files into a ZIP-file (or similar). Now, I know how to access that data from C++, but I'm unsure what interface I have to implement to make the content available to QML. Is QIODevice the way to go? If yes, how can I get it to work with QUrl?

    Currently my C++ backend has properties like:
    @ Q_PROPERTY(QUrl image READ getImage NOTIFY imageChanged); @

    And in QML I'm doing:
    @
    Image {
    source: backend.image
    }
    @

    I hope to be able to keep all that code and transparently access the ZIP file instead of the resource file. If that does not work it would also be ok for me to change the URLs to something like zip:///somedir/image.jpg

    It would be great if you could give me some pointers in the right direction. Especially the QUrl/QML integration.

    Thanks!
    Conny

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      A couple of options:

      Use multiple resource files rather than one huge one if you are running out of memory at the compilation stage.

      Take a look at "QAbstractFileEngineHandler":http://doc.qt.nokia.com/latest/qabstractfileenginehandler.html and "QAbstractFileEngine":http://doc.qt.nokia.com/latest/qabstractfileengine.html classes to implement your own virtual file system. You could wrap up some existing format (zip, tarball, mpq) or invent your own. This approach will allow you to use your own URL prefix as you mentioned above.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • C Offline
        C Offline
        conny
        wrote on last edited by
        #3

        [quote author="ZapB" date="1301817472"]

        Use multiple resource files rather than one huge one if you are running out of memory at the compilation stage.[/quote]

        I have around 100MB and from my experience it can take ages to compile that even if you have enough RAM, so I think option 2 is better suited.

        [quote author="ZapB" date="1301817472"] # Take a look at "QAbstractFileEngineHandler":http://doc.qt.nokia.com/latest/qabstractfileenginehandler.html and "QAbstractFileEngine":http://doc.qt.nokia.com/latest/qabstractfileengine.html classes to implement your own virtual file system. You could wrap up some existing format (zip, tarball, mpq) or invent your own. This approach will allow you to use your own URL prefix as you mentioned above.[/quote]

        That looks like exactly what I need. I'll start trying this with zip since I think it's better suited for random-access than tar.

        Thanks a lot!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          attila.katona
          wrote on last edited by
          #4

          Hi,

          I would also need to group some files and directories (images, xml,...) into one container file. I just can not find out, how should I do it with QAbstractFileEngineHandler and QAbstractFileEngine. Could you give me a small example? (Here is my example)

          @class MyContainer : public QFSFileEngine
          {
          public:
          MyContainer( const QString & fn ) : QFSFileEngine( fn ){
          setFileName( " CONTAINER FILE " );
          }

              QString getInfos()
              {
                  // I would like to have a folderstructure with some files:
                  //
                  //--container
                  //    |
                  //    -- header
                  //        |
                  //        -- infos.txt
          
                  return "";
              }
          

          };

          class MyContainerHandler : public QAbstractFileEngineHandler
          {
          public:
          QAbstractFileEngine *create(const QString &fileName) const;
          };

          QAbstractFileEngine *MyContainerHandler::create(const QString &fileName) const
          {
          return fileName.toLower().endsWith(".container") ? new MyContainer(fileName) : 0;
          }@

          Thanks,
          Attlia

          1 Reply Last reply
          0
          • M Offline
            M Offline
            moellney
            wrote on last edited by
            #5

            Note that in
            http://labs.qt.nokia.com/2011/05/12/qt-modules-maturity-level-the-list/

            you can read:

            Abstract file engines
            State: Deprecated
            Reasoning: flawed design, this is the wrong level to provide a virtual filesystem, so we don’t recommend taking this over. In Qt 5, this functionality will be Removed.

            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