FileView: QtObject
import Quickshell.Io
Simplified reader for small files. More
Properties
Functions
Signals
Detailed Description
A reader for small to medium files that don’t need seeking/cursor access, suitable for most text files.
Example: Reading a JSON
FileView {
id: jsonFile
path: Qt.resolvedUrl("./your.json")
// Forces the file to be loaded by the time we call JSON.parse().
// see blockLoading's property documentation for details.
blockLoading: true
}
readonly property var jsonData: JSON.parse(jsonFile.text())
Property Details
blockAllReads: bool
If text() and data() should block all operations while a file loads. Defaults to false.
This is nearly identical to blockLoading, but will additionally block when a file is loaded and path changes.
blockLoading: bool
If text() and data() should block all operations until the file is loaded. Defaults to false.
If the file is already loaded, no blocking will occur. If a file was loaded, and path was changed to a new file, no blocking will occur.
Blocking operations should be used carefully to avoid stutters and other performance degradations. Blocking means that your interface WILL NOT FUNCTION during the call.
We recommend you use a blocking load ONLY for files loaded before the windows of your shell
are loaded, which happens after Component.onCompleted
runs for the root component of your shell.
The most reasonable use case would be to load things like configuration files that the program must have available.
loaded: bool
If a file is currently loaded, which may or may not be the one currently specified by path.
path: string
The path to the file that should be read, or an empty string to unload the file.
preload: bool
If the file should be loaded in the background immediately when set. Defaults to true.
This may either increase or decrease the amount of time it takes to load the file depending on how large the file is, how fast its storage is, and how you access its data.
Function Details
bool blockUntilLoaded()
Block all operations until the currently running load completes.
unknown data()
Returns the data of the file specified by path as an ArrayBuffer.
If blockAllReads is true, all changes to path will cause the program to block when this function is called.
If blockLoading is true, reading this property before the file has been loaded will block, but changing path or calling reload() will return the old data until the load completes.
If neither is true, an empty buffer will be returned if no file is loaded, otherwise it will behave as in the case above.
dataChanged()
is present.
void reload()
Unload the loaded file and reload it, usually in response to changes.
This will not block if blockLoading is set, only if blockAllReads is true. It acts the same as changing path to a new file, except loading the same file.
string text()
Returns the data of the file specified by path as text.
If blockAllReads is true, all changes to path will cause the program to block when this function is called.
If blockLoading is true, reading this property before the file has been loaded will block, but changing path or calling reload() will return the old data until the load completes.
If neither is true, an empty string will be returned if no file is loaded, otherwise it will behave as in the case above.
textChanged()
is present.
Signal Details
loadFailed()
! Fires if the file failed to load. A warning will be printed in the log.