Use QUrl for file paths

This commit is contained in:
Fabien Freling 2019-07-16 10:04:05 +02:00
parent 3b9085545b
commit 90526946e6
2 changed files with 8 additions and 8 deletions

View file

@ -1,7 +1,8 @@
#include "oboy.h"
#include <QtGlobal>
#include <QCoreApplication>
#include <QUrl>
#include <QtGlobal>
#include <caml/mlvalues.h>
#include <caml/callback.h>
@ -15,7 +16,8 @@ OBoy::OBoy(QObject *parent) : QObject(parent)
{
const QStringList args = QCoreApplication::arguments();
if (args.size() > 1) {
load(args.at(1));
const QUrl path = QUrl::fromLocalFile(args.at(1));
load(path);
}
}
@ -60,8 +62,7 @@ QString OBoy::version() const
return QString(str);
}
bool OBoy::load(const QString &path)
{
bool OBoy::load(const QUrl &path) {
CAMLparam0();
CAMLlocal1(ocaml_path) ;
@ -71,9 +72,8 @@ bool OBoy::load(const QString &path)
return false;
}
QString truncated(path);
truncated.remove(0, 7); // remove file://
QByteArray ba = truncated.toLocal8Bit();
const QString local_path = path.toLocalFile();
const QByteArray ba = local_path.toLocal8Bit();
ocaml_path = caml_copy_string_of_os(ba.data());

View file

@ -16,7 +16,7 @@ public:
QString name() const;
QString version() const;
bool loaded() const;
Q_INVOKABLE bool load(const QString &path);
Q_INVOKABLE bool load(const QUrl &path);
QImage backgroundMap(int index) const;
signals: