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

View file

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