diff options
author | Alessandro Portale <alessandro.portale@qt.io> | 2019-08-08 09:25:03 +0200 |
---|---|---|
committer | Alessandro Portale <alessandro.portale@qt.io> | 2019-08-08 18:07:19 +0200 |
commit | 9a34bdb625bd5d8a62ec77aab73a19bf8b2d92b4 (patch) | |
tree | b77a639a6a228a799ec6a34152bf5324f54d3e3f | |
parent | 4b368fba370c1be7269fb3834df4f34885613462 (diff) |
Notify errors via alert()
...instead of just printing it to the console
-rw-r--r-- | main.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -66,6 +66,14 @@ void fetchProject(QByteArray *data, QString *fileName) ["number", "number", "string"], [heapPointer, contentSize, projectfileName]); }); } + +void printError(const QString &error) +{ + QString escaped = error; + escaped.replace("'", "\'"); + escaped.replace("\n", "\\n"); + emscripten_run_script("alert('" + escaped.toUtf8() + "');"); +} #else // Q_OS_WASM void fetchProject(QByteArray *data, QString *fileName) @@ -80,6 +88,11 @@ void fetchProject(QByteArray *data, QString *fileName) if (file.open(QIODevice::ReadOnly)) *data = file.readAll(); } + +void printError(const QString &error) +{ + fprintf(stderr, "%s\n", qPrintable(error)); +} #endif // Q_OS_WASM void unpackProject(const QByteArray &project, const QString &targetDir) @@ -166,13 +179,13 @@ int main(int argc, char *argv[]) component->loadUrl(mainQmlUrl); while (component->isLoading()) QCoreApplication::processEvents(); - if (!component->isReady() ) { - fprintf(stderr, "%s\n", qPrintable(component->errorString())); + if (!component->isReady()) { + printError(component->errorString()); return -1; } QObject *topLevel = component->create(); if (!topLevel && component->isError()) { - fprintf(stderr, "%s\n", qPrintable(component->errorString())); + printError(component->errorString()); return -1; } QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(topLevel)); |