[Interest] Routing all QML file requests through a custom resource provider

Max Savenkov max.savenkov at gmail.com
Fri Jun 17 11:09:40 CEST 2016


Hello,

Once again, I'm trying to use Qt (in this case, QtQuick/QML) for game 
development. The game is going to store all its resources in a package 
(it might be zip, or a custom format) when deployed, but during 
development, resources are available in the usual filesystem. This 
difference is hidden by game's resource provider, which maps resource 
name to a file or an entry in package.

This works for the game itself, but how can I make QML load images, 
imports and other resources from game's resource provider? (also, I'd 
like to view my QML files in Designer, which means I can't use custom 
image providers in QML code itself)

I see two possibilities, but I'm not sure of either one.

1) Use dynamic resources produced by rcc. When loading a QML file from 
C++, also load relevant rcc data (from game's resources) and register it 
with Qt resource system to make it accessible. This sounds workable, but 
I'm not sure how exactly to make it happen. Suppose I got a binary 
buffer from game's resources. How do I register it in Qt?

2) Use a system of crutches.
* Register Url Interceptor with my QMLEngine, such that:
     - any URL that contains an image is changed into 
"image:/my_resource_provider/imagename.png"
     - any URL that contains qml or qmldir is change into... What? There 
is no way to register a special loader for QML imports. But I guess I 
can change it into a network request, by substituting shcema to, for 
example, "my_provider"
* Register image provider with name "my_resource_provider" that loads 
images from my resource system.
* Register a custom network access manager factory/manager/network reply 
that load QML files from my system instead of network. This doesn't 
quite work, however, because QML at some point for whatever reason 
checks that URL used to load qml file is local...

So, I'm stumped. This should be WAY easier... And it was, before 
AbstractFileEngine was made private. But I really don't want to use 
private APIs if I can avoid it.
An argument against AbstractFileEngine was made, that virtual FS should 
be implemented "at OS level" - but I simply cannot see how a game can 
implement it at OS level, because it's a game 0_o.



More information about the Interest mailing list