C

File system integration

Implementing a file system integration for Qt Quick Ultralite

To load resources from a file system, an implementation must be registered with the application. It has to implement the Qul::PlatformInterface::Filesystem and Qul::PlatformInterface::File classes. An example implementation for the FatFS file system can be found in examples/fileloading/fatfs/fatfsfilesystem.h

The following code shows example implementations for these classes:

class MyFile : public Qul::PlatformInterface::File
{
public:
    MyFile(fileHandle) {...}
    uint64_t size();
    int read(unsigned char *outputBuffer, uint64_t startOffset, unsigned int size);
    int close();
}
uint64_t MyFile::size()
{
    return file_size;
}
int MyFile::read(unsigned char *outputBuffer, uint64_t startOffset, unsigned int readSize)
{
    int bytesRead;

    if (file_seek(startOffset) != OK)
        return -1;

    if (file_read(outputBuffer, readSize, &bytesRead) != OK)
        return -1;

    return bytesRead;
}
int MyFile::close()
{
    return file_close();
}

To integrate the file with the application API, it has to be wrapped in a file system.

class MyFilesystem : public Qul::PlatformInterface::Filesystem
{
public:
    Qul::PlatformInterface::File *open(const char *fileName, Qul::PlatformInterface::File::Mode)
    {
        if (file_open(fileName, mode) != OK)
            return NULL;

        return Qul::PlatformInterface::qul_new<MyFile>(handle);
    }
};

To make the implemented file system known to Qt Quick Ultralite, it has to be registered with the application.

static MyFilesystem filesystem;
Qul::Application::addFilesystem(&filesystem);

Qt Quick Ultralite will iterate all registered file systems until the first returns a file instance.

Available under certain Qt licenses.
Find out more.