jsonreader.cpp 618 Bytes
Newer Older
1 2 3 4 5
#include "jsonreader.h"

JSONReader::JSONReader(QObject *parent) : QObject(parent) {}

QString JSONReader::read() {
rahulde's avatar
rahulde committed
6 7 8 9 10
    jsonFile = jsonFile.replace("file://", "");

    if (jsonFile == "")
        return QString();

11 12 13 14 15 16 17 18 19
    if (jsonFile.isEmpty()) {
        emit error("source is empty");
        return QString();
    }

    QFile file(jsonFile);
    QString fileContent;

    if (file.open(QIODevice::ReadOnly)) {
20
        QTextStream t(&file);
rahulde's avatar
rahulde committed
21
        fileContent = t.readAll();
22 23 24 25 26 27 28 29
        file.close();
    } else {
        emit error("Unable to open the file");
        return QString();
    }

    return fileContent;
}