MuseScore  3.4
Music composition and notation
Public Slots | Signals | Public Member Functions | Properties | Private Attributes | List of all members
Ms::PluginAPI::FileIO Class Reference

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

#include <util.h>

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

Public Slots

void setSource (const QString &source)
 

Signals

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

Public Member Functions

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

Properties

QString source
 Path to the file which is operated on. More...
 

Private Attributes

QString mSource
 

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 {
id: exampleFile
source: "/tmp/example.txt"
}
onRun: {
var test = exampleFile.read();
console.log(test); // will print the file content
}
}

Constructor & Destructor Documentation

◆ FileIO()

Ms::PluginAPI::FileIO::FileIO ( QObject *  parent = 0)
explicit

Member Function Documentation

◆ error

void Ms::PluginAPI::FileIO::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.

◆ exists()

bool Ms::PluginAPI::FileIO::exists ( )

Returns true if the file exists.

◆ homePath()

Q_INVOKABLE QString Ms::PluginAPI::FileIO::homePath ( )
inline

Returns user's home directory.

◆ modifiedTime()

int Ms::PluginAPI::FileIO::modifiedTime ( )

Returns the file's last modification time.

◆ read()

QString Ms::PluginAPI::FileIO::read ( )

Reads file contents and returns a string.

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

◆ remove()

bool Ms::PluginAPI::FileIO::remove ( )

Removes the file.

◆ setSource

void Ms::PluginAPI::FileIO::setSource ( const QString &  source)
inlineslot

◆ source()

QString Ms::PluginAPI::FileIO::source ( )
inline

◆ tempPath()

Q_INVOKABLE QString Ms::PluginAPI::FileIO::tempPath ( )
inline

Returns a path suitable for a temporary file.

◆ write()

bool Ms::PluginAPI::FileIO::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.

Member Data Documentation

◆ mSource

QString Ms::PluginAPI::FileIO::mSource
private

Property Documentation

◆ source

QString Ms::PluginAPI::FileIO::source
readwrite

Path to the file which is operated on.


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