summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <[email protected]>2025-08-08 14:27:13 +0200
committerUlf Hermann <[email protected]>2025-08-13 17:02:33 +0200
commit48f37a8e66320570c34034fd3b748f5c6f02609e (patch)
tree6d3198de73262e5a1a36f4d02199075fb3f3a0f0
parent43606bb8ec7902e3bb3b642ce7fd1c8398922232 (diff)
Port away from QQmlFileHEADdev
The usage of QQmlFile was pointless there because we only accept local files anyway. Change-Id: I8e09723c086898f99574fb62ac86db1aee852ad1 Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--src/scxmlqml/statemachineloader.cpp40
-rw-r--r--tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp7
2 files changed, 17 insertions, 30 deletions
diff --git a/src/scxmlqml/statemachineloader.cpp b/src/scxmlqml/statemachineloader.cpp
index 35be828..341bef8 100644
--- a/src/scxmlqml/statemachineloader.cpp
+++ b/src/scxmlqml/statemachineloader.cpp
@@ -4,11 +4,13 @@
#include "statemachineloader_p.h"
#include <QtScxml/qscxmlstatemachine.h>
-#include <qqmlcontext.h>
-#include <qqmlengine.h>
-#include <qqmlinfo.h>
-#include <qqmlfile.h>
-#include <qbuffer.h>
+
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlfile.h>
+#include <QtQml/qqmlinfo.h>
+
+#include <QtCore/qfile.h>
/*!
\qmltype StateMachineLoader
@@ -147,32 +149,16 @@ bool QScxmlStateMachineLoader::parse(const QUrl &source)
.arg(source.url());
return false;
}
- QQmlFile scxmlFile(QQmlEngine::contextForObject(this)->engine(), source);
- if (scxmlFile.isError()) {
- // the synchronous case can only fail when the file is not found (or not readable).
- qmlWarning(this) << QStringLiteral("Cannot open '%1' for reading.").arg(source.url());
- return false;
- }
- QByteArray data(scxmlFile.dataByteArray());
- QBuffer buf(&data);
- if (!buf.open(QIODevice::ReadOnly)) {
- qmlWarning(this) << QStringLiteral("Cannot open input buffer for reading");
+ const QString fileName = QQmlFile::urlToLocalFileOrQrc(source);
+ QFile file(fileName);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qmlWarning(this) << QStringLiteral("Cannot open '%1' for reading: %2")
+ .arg(fileName, file.errorString());
return false;
}
- QString fileName;
- if (source.isLocalFile()) {
- fileName = source.toLocalFile();
- } else if (source.scheme() == QStringLiteral("qrc")) {
- fileName = QStringLiteral(":") + 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.");
- }
-
- auto stateMachine = QScxmlStateMachine::fromData(&buf, fileName);
+ auto stateMachine = QScxmlStateMachine::fromData(&file, fileName);
stateMachine->setParent(this);
m_implicitDataModel = stateMachine->dataModel();
diff --git a/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp b/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp
index d723ee9..b6c4b87 100644
--- a/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp
+++ b/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp
@@ -145,9 +145,10 @@ void tst_scxmlqmlcpp::stateMachineLoaderSourceStateMachineBinding()
QUrl sourceBroken(testFileUrl("brokenstatemachine.scxml"));
QVERIFY(sml->stateMachine() != nullptr);
- QTest::ignoreMessage(QtWarningMsg,
- qPrintable(smlUrl.toString() + ":5:5: QML StateMachineLoader: " +
- "Cannot open '" + sourceNonexistent.toString() + "' for reading."));
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(
+ smlUrl.toString() + ":5:5: QML StateMachineLoader: " +
+ "Cannot open '" + testFile("file_doesnt_exist.scxml") +
+ "' for reading: .*"));
sml->setSource(sourceNonexistent);
QVERIFY(sml->stateMachine() == nullptr);
QCOMPARE(smSpy.size(), 1);