vnote/utils/vutils.cpp
Le Tan 7bce2cb298 use QWebEngineView to display markdown files
Thanks to [marked JavaScript library](https://github.com/chjj/marked) by
Christopher Jeffrey. The
[style sheet](http://kevinburke.bitbucket.org/markdowncss/markdown.css)
was created by Kevin Burke.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
2016-10-09 20:47:20 +08:00

36 lines
861 B
C++

#include "vutils.h"
#include <QFile>
#include <QDebug>
VUtils::VUtils()
{
}
QString VUtils::readFileFromDisk(const QString &filePath)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "error: fail to read file" << filePath;
return QString();
}
QString fileText(file.readAll());
file.close();
qDebug() << "read file content:" << filePath;
return fileText;
}
bool VUtils::writeFileToDisk(const QString &filePath, const QString &text)
{
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "error: fail to open file" << filePath << "to write to";
return false;
}
QTextStream stream(&file);
stream << text;
file.close();
qDebug() << "write file content:" << filePath;
return true;
}