MuseScore Plugins  3.5
Plugins API for MuseScore
Signals | Public Member Functions | Properties | List of all members
FileIO Class Reference

Provides a simple API to perform file reading and writing operations. More...

Inheritance diagram for FileIO:
Inheritance graph
[legend]
Collaboration diagram for FileIO:
Collaboration graph
[legend]

Signals

void error (const QString &msg)
 Emitted on file operations errors. More...
 

Public Member Functions

Q_INVOKABLE QString read ()
 Reads file contents and returns a string. More...
 
Q_INVOKABLE bool exists ()
 Returns true if the file exists.
 
Q_INVOKABLE bool write (const QString &data)
 Writes a string to the file. More...
 
Q_INVOKABLE bool remove ()
 Removes the file.
 
Q_INVOKABLE QString homePath ()
 Returns user's home directory.
 
Q_INVOKABLE QString tempPath ()
 Returns a path suitable for a temporary file.
 
Q_INVOKABLE int modifiedTime ()
 Returns the file's last modification time.
 

Properties

QString source
 Path to the file which is operated on.
 

Detailed Description

Provides a simple API to perform file reading and writing operations.

To use this class in a plugin put

import FileIO 3.0

to the top part of the .qml plugin file. After that FileIO object can be declared and used in QML code:

import MuseScore 3.0
import FileIO 3.0
MuseScore {
FileIO {
id: exampleFile
source: "/tmp/example.txt"
}
onRun: {
var test = exampleFile.read();
console.log(test); // will print the file content
}
}

Member Function Documentation

◆ error

void error ( const QString &  msg)
signal

Emitted on file operations errors.

Implement onError() in your FileIO object to handle this signal.

Parameters
msgA short textual description of the error occurred.

◆ read()

QString read ( )

Reads file contents and returns a string.

In case error occurs, error() signal is emitted and an empty string is returned.

◆ write()

bool write ( const QString &  data)

Writes a string to the file.

Warning
This function overwrites all the contents of the file pointed by FileIO::source so it becomes lost.
Returns
true if an operation finished successfully.

The documentation for this class was generated from the following files: