Change file handling code to open file depending on url type.
This commit is contained in:
@@ -32,11 +32,17 @@ JsonIO::JsonIO(SqlVehicle* vehicles, SqlServiceRecord* records, QObject* parent)
|
||||
|
||||
bool JsonIO::importCarfaxJsonToDB(QString fileLocation)
|
||||
{
|
||||
QFile file(QUrl(fileLocation).toLocalFile());
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QUrl url(fileLocation);
|
||||
QFile *file;
|
||||
if(url.scheme() == "file") {
|
||||
file = new QFile(url.toLocalFile());
|
||||
} else {
|
||||
file = new QFile(url.toString());
|
||||
}
|
||||
file->open(QIODevice::ReadOnly);
|
||||
QString jsonContent;
|
||||
jsonContent = file.readAll();
|
||||
file.close();
|
||||
jsonContent = file->readAll();
|
||||
file->close();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonContent.toUtf8());
|
||||
QJsonObject root = doc.object();
|
||||
if(root.contains("vehicle")) {
|
||||
|
||||
Reference in New Issue
Block a user