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