I am creating a 3ds model loader using Qt.
I want to take advantage of the Qt resource system and use it for loading models and such.
I would like to do syntax similar to this:
Mesh* MeshLoader::loadMesh(const QString& resource) {
QResource qResource(resource);
QResource::registerResource(resource);
SomeBuffer buffer(qResource.data())
while (!buffer.eof()) {
// Process the file
}
QResource::unregisterResource(resource);
}
Any suggestions?
And what’s the problem with the code you included in you post?
Just as a note: you can use the Qt resource notation (the leading : in the path) with pretty much every Qt data/stream reader. For example you can use QFile(“:/someresource”). With QFile and QDataStream I think (but maybe I’m wrong) you can read only chunks of the file without loading the whole resource and blocking the thread during reading. If it blocks the main-thread you can always use QRunnable or QThread to load resources in background.
For the buffering: I don’t know any caching solution built into Qt (except in the networking related parts), so you should probably implement it for yourself.
This way you can build a MyResource class which loads the target resource in a background thread and notifies with signal/slot when it’s finished and can cache the resource’s data the way you want.