From 8d57bfb1aef3b71557bc408154ee028751fd688e Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 14 Jun 2021 19:09:53 +0200 Subject: First commit There was history before but now there is no more. --- io.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 io.h (limited to 'io.h') diff --git a/io.h b/io.h new file mode 100644 index 0000000..0d9b238 --- /dev/null +++ b/io.h @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Unlicense + +#ifndef IO_H +#define IO_H + +#include +#include +#include +#include +#include + +class IO : public QObject { + Q_OBJECT +public slots: + void write(const QUrl &url, const QString &data) { + QFile file{urlToPath(url)}; + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + file.write(data.toUtf8()); + else + qWarning() << "error opening file" << url; + } + + QString read(const QUrl &url) { + QFile file{urlToPath(url)}; + if (file.open(QIODevice::ReadOnly)) + return file.readAll(); + qWarning() << "error opening file" << url; + return {}; + } + +private: + static const QString urlToPath(const QUrl &path) { + return path.scheme() == "qrc" ? (":" + path.path()) : path.toLocalFile(); + } +}; + +#endif -- cgit v1.3