Change file handling code to open file depending on url type.

This commit is contained in:
2020-07-23 11:25:03 -04:00
parent 3c8a3ee04c
commit edb48c6802

View File

@@ -32,11 +32,17 @@ JsonIO::JsonIO(SqlVehicle* vehicles, SqlServiceRecord* records, QObject* parent)
bool JsonIO::importCarfaxJsonToDB(QString fileLocation) bool JsonIO::importCarfaxJsonToDB(QString fileLocation)
{ {
QFile file(QUrl(fileLocation).toLocalFile()); QUrl url(fileLocation);
file.open(QIODevice::ReadOnly); QFile *file;
if(url.scheme() == "file") {
file = new QFile(url.toLocalFile());
} else {
file = new QFile(url.toString());
}
file->open(QIODevice::ReadOnly);
QString jsonContent; QString jsonContent;
jsonContent = file.readAll(); jsonContent = file->readAll();
file.close(); file->close();
QJsonDocument doc = QJsonDocument::fromJson(jsonContent.toUtf8()); QJsonDocument doc = QJsonDocument::fromJson(jsonContent.toUtf8());
QJsonObject root = doc.object(); QJsonObject root = doc.object();
if(root.contains("vehicle")) { if(root.contains("vehicle")) {