From a1dff1a11ad303a1f82f181e6386194de90ec08f Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 17 Aug 2017 15:55:54 +0200 Subject: Properly convert URLs to local files in QML state machine loader toString() doesn't do what we're looking for. "file:" URLs can be readily converted to local files, "qrc:" URLs can be converted by prepending a ":" to their path component. All others cannot. In order to support those, we'd have to extend QScxmlCompiler to accept generic URLs rather than file names, and then we still might not be able to actually resolve relative file names from tags. Change-Id: I138318e8abd87e6e097445f77148668439ff980c Task-number: QTBUG-62178 Reviewed-by: Jarek Kobus --- src/imports/scxmlstatemachine/statemachineloader.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/imports/scxmlstatemachine/statemachineloader.cpp b/src/imports/scxmlstatemachine/statemachineloader.cpp index 946988f..0d28e6c 100644 --- a/src/imports/scxmlstatemachine/statemachineloader.cpp +++ b/src/imports/scxmlstatemachine/statemachineloader.cpp @@ -163,7 +163,18 @@ bool QScxmlStateMachineLoader::parse(const QUrl &source) return false; } - m_stateMachine = QScxmlStateMachine::fromData(&buf, source.toString()); + QString fileName; + if (source.isLocalFile()) { + fileName = source.toLocalFile(); + } else if (source.scheme() == QStringLiteral("qrc")) { + fileName = ":" + source.path(); + } else { + qmlWarning(this) << QStringLiteral("%1 is neither a local nor a resource URL.") + .arg(source.url()) + << QStringLiteral("Invoking services by relative path will not work."); + } + + m_stateMachine = QScxmlStateMachine::fromData(&buf, fileName); m_stateMachine->setParent(this); m_implicitDataModel = m_stateMachine->dataModel(); -- cgit v1.2.3 From 3d23818472e371745f4ad4bd4b6c92de3d119e34 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 15 Mar 2017 16:22:18 +0100 Subject: Output a better warning when runtime-loading malformed SCXML The document might technically have a root element. We might not be able to read it, though. Also, output all errors without quotes. Change-Id: I8133e322e452ea0c3d079b5cbe23aed2f2952b3e Reviewed-by: Erik Verbruggen --- src/scxml/qscxmlcompiler.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/scxml/qscxmlcompiler.cpp b/src/scxml/qscxmlcompiler.cpp index 626015b..f259eee 100644 --- a/src/scxml/qscxmlcompiler.cpp +++ b/src/scxml/qscxmlcompiler.cpp @@ -685,7 +685,7 @@ QScxmlScxmlService *invokeDynamicScxmlService(const QString &sourceUrl, if (!compiler.errors().isEmpty()) { const auto errors = compiler.errors(); for (const QScxmlError &error : errors) - qWarning() << error.toString(); + qWarning().noquote() << error.toString(); return Q_NULLPTR; } @@ -694,7 +694,7 @@ QScxmlScxmlService *invokeDynamicScxmlService(const QString &sourceUrl, Q_ASSERT(!compiler.errors().isEmpty()); const auto errors = compiler.errors(); for (const QScxmlError &error : errors) - qWarning() << error.toString(); + qWarning().noquote() << error.toString(); return Q_NULLPTR; } @@ -847,7 +847,12 @@ void QScxmlCompilerPrivate::instantiateDataModel(QScxmlStateMachine *stateMachin #ifdef BUILD_QSCXMLC Q_UNUSED(stateMachine) #else - auto doc = scxmlDocument(); + if (!m_errors.isEmpty()) { + qWarning() << "SCXML document has errors"; + return; + } + + auto doc = m_doc.data(); auto root = doc ? doc->root : Q_NULLPTR; if (root == Q_NULLPTR) { qWarning() << "SCXML document has no root element"; -- cgit v1.2.3