Resource Class | Qt Installer Framework Manual

- Qt Installer Framework Manual
- Resource

# Resource Class

class QInstaller::Resource

The Resource class is an interface for wrapping a file as read only device. More...

Header: | #include <Resource>

- List of all members, including inherited members

## Public Functions

| Resource(const QString &path)
| Resource(const QString &path, const QByteArray &name)
| Resource(const QString &path, const Range<qint64> &segment)
virtual | ~Resource()
void | copyData(QFileDevice *out)
QByteArray | name() const
bool | open(std::optional<QFile::Permissions> permissions = std::nullopt)
Range<qint64> | segment() const
void | setName(const QByteArray &name)
void | setSegment(const Range<qint64> &segment)

## Reimplemented Public Functions

virtual void | close() override
virtual bool | seek(qint64 pos) override
virtual qint64 | size() const override

## Static Public Members

void | copyData(QInstaller::Resource *resource, QFileDevice *out)

## Detailed Description

Resource is an interface for reading inside a file, but is not supposed to write to the file it wraps. The `Resource` class is created by passing a path to an existing binary (such as a zipped archive or a Qt resource file).

The resource name can be set at any time using setName() or during construction. The segment supplied during construction represents the offset and size of the resource inside the file.

## Member Function Documentation

### `[explicit]` Resource::Resource(const QString &path)

Creates a resource providing the data in path.

### Resource::Resource(const QString &path, const QByteArray &name)

Creates a resource providing the data in path identified by name.

### Resource::Resource(const QString &path, const Range<qint64> &segment)

Creates a resource providing the data in path limited to segment.

### `[virtual noexcept]` Resource::~Resource()

Destroys the resource. Calls close() if necessary before destroying the resource.

### `[override virtual]` void Resource::close()

### void Resource::copyData(QFileDevice *out)

Copies the resource data to a file called out. Throws Error on failure.

### `[static]` void Resource::copyData(QInstaller::Resource *resource, QFileDevice *out)

This is an overloaded function.

Copies the resource data of resource to a file called out. Throws Error on failure.

### QByteArray Resource::name() const

Returns the name of the resource.

See also setName().

### bool Resource::open(std::optional<QFile::Permissions> permissions = std::nullopt)

Opens a resource in QIODevice::ReadOnly mode. The function returns `true` if successful.

### `[override virtual]` bool Resource::seek(qint64 pos)

### Range<qint64> Resource::segment() const

Returns the range inside the file this resource represents.

See also setSegment().

### void Resource::setName(const QByteArray &name)

Sets the name of the resource to name.

See also name().

### void Resource::setSegment(const Range<qint64> &segment)

Sets the range to the segment of the file that this resource represents.

See also segment().

### `[override virtual]` qint64 Resource::size() const