KIO::FileJob Class

class KIO::FileJob
Header: #include <KIO/FileJob>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KF6::KIOCore)
Inherits: KIO::SimpleJob

Public Functions

void close()
void read(KIO::filesize_t size)
void seek(KIO::filesize_t offset)
KIO::filesize_t size()
(since 5.66) void truncate(KIO::filesize_t length)
void write(const QByteArray &data)

Signals

void data(KIO::Job *job, const QByteArray &data)
(since 5.79) void fileClosed(KIO::Job *job)
(since 5.78) void mimeTypeFound(KIO::Job *job, const QString &mimeType)
void open(KIO::Job *job)
void position(KIO::Job *job, KIO::filesize_t offset)
void redirection(KIO::Job *job, const QUrl &url)
(since 5.66) void truncated(KIO::Job *job, KIO::filesize_t length)
void written(KIO::Job *job, KIO::filesize_t written)
KIO::FileJob *open(const QUrl &url, QIODeviceBase::OpenMode mode)

Detailed Description

The file-job is an asynchronous version of normal file handling. It allows block-wise reading and writing, and allows seeking and truncation. Results are returned through signals.

Should always be created using KIO::open(const QUrl&, QIODevice::OpenMode).

Member Function Documentation

void FileJob::close()

Closes the file KIO worker.

The worker emits close() and result().

[signal] void FileJob::data(KIO::Job *job, const QByteArray &data)

Data from the worker has arrived. Emitted after read().

Unless a read() request was sent for 0 bytes, End of data (EOD) has been reached if data.size() == 0

job the job that emitted this signal

data data received from the worker.

[signal, since 5.79] void FileJob::fileClosed(KIO::Job *job)

Signals that the file is closed and will accept no more commands.

job the job that emitted this signal

This function was introduced in 5.79.

[signal, since 5.78] void FileJob::mimeTypeFound(KIO::Job *job, const QString &mimeType)

MIME type determined.

job the job that emitted this signal

mimeType the MIME type

This function was introduced in 5.78.

[signal] void FileJob::open(KIO::Job *job)

File is open, metadata has been determined and the file KIO worker is ready to receive commands.

job the job that emitted this signal

Note: Signal open is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

connect(fileJob, QOverload<KIO::Job *>::of(&FileJob::open),
    [=](KIO::Job *job){ /* ... */ });

[signal] void FileJob::position(KIO::Job *job, KIO::filesize_t offset)

The file has reached this position. Emitted after seek().

job the job that emitted this signal

offset the new position

void FileJob::read(KIO::filesize_t size)

This function attempts to read up to size bytes from the URL passed to KIO::open() and returns the bytes received via the data() signal.

The read operation commences at the current file offset, and the file offset is incremented by the number of bytes read, but this change in the offset does not result in the position() signal being emitted.

If the current file offset is at or past the end of file (i.e. EOD), no bytes are read, and the data() signal returns an empty QByteArray.

On error the data() signal is not emitted. To catch errors please connect to the result() signal.

[signal] void FileJob::redirection(KIO::Job *job, const QUrl &url)

Signals the file is a redirection. Follow this url manually to reach data

job the job that emitted this signal

url the new URL

void FileJob::seek(KIO::filesize_t offset)

Seek

The worker emits position() on successful seek to the specified offset.

On error the position() signal is not emitted. To catch errors please connect to the result() signal.

KIO::filesize_t FileJob::size()

Returns the file size

[since 5.66] void FileJob::truncate(KIO::filesize_t length)

Truncate

The worker emits truncated() on successful truncation to the specified \p length.

On error the truncated() signal is not emitted. To catch errors please connect to the result() signal.

This function was introduced in 5.66.

[signal, since 5.66] void FileJob::truncated(KIO::Job *job, KIO::filesize_t length)

The file has been truncated to this point. Emitted after truncate().

job the job that emitted this signal

length the new length of the file

This function was introduced in 5.66.

void FileJob::write(const QByteArray &data)

This function attempts to write all the bytes in data to the URL passed to KIO::open() and returns the bytes written received via the written() signal.

The write operation commences at the current file offset, and the file offset is incremented by the number of bytes read, but this change in the offset does not result in the position() being emitted.

On error the written() signal is not emitted. To catch errors please connect to the result() signal.

[signal] void FileJob::written(KIO::Job *job, KIO::filesize_t written)

written bytes were written to the file. Emitted after write().

job the job that emitted this signal

written bytes written.

Related Non-Members

KIO::FileJob *open(const QUrl &url, QIODeviceBase::OpenMode mode)

Open ( random access I/O )

The file-job emits open() when opened

On error the open() signal is not emitted. To catch errors please connect to the result() signal.

url the URL of the file

mode the access privileges: see OpenMode

Returns the file-handling job. It will never return 0. Errors are handled asynchronously (emitted as signals).