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)
|
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")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user