35 #include <QTextStream> 49 QUrl url = QUrl( _path);
50 if (_path.isEmpty() || !url.isLocalFile()){
51 emit
error(
"Invalid fileName=" + _path);
54 QString
path = url.toLocalFile();
58 if (file.open(QIODevice::ReadOnly)) {
60 QTextStream ts( &file);
63 fileContent += ((fileContent.size() > 0) && !line.isNull()) ?
"\n" :
"";
65 }
while (!line.isNull());
70 emit
error(
"Can't' open file, path=" +
path);
83 if (!file.open(QFile::WriteOnly | QFile::Truncate))
86 QTextStream out( &file);
97 QUrl url = QUrl( _path);
98 if (_path.isEmpty() || !url.isLocalFile()){
99 emit
error(
"Invalid fileName=" + _path);
102 QString
path = url.path();
105 QByteArray fileContent;
106 if (file.open( QIODevice::ReadOnly) ) {
107 fileContent = file.readAll();
111 emit
error(
"Can't' open file, path=" +
path);
124 if (!file.open(QFile::WriteOnly | QFile::Truncate))
QmlMFileIO(QObject *parent=arnNullptr)
void pathChanged(const QString &path)
void setPath(const QString &path)
Q_INVOKABLE bool write(const QString &data)
Q_INVOKABLE QByteArray readBytes()
Q_INVOKABLE QString read()
void error(const QString &msg)
Q_INVOKABLE bool writeBytes(const QByteArray &data)