fix: null check qmlEngine() in CUtils::saveItem

qmlEngine(this) can return nullptr during engine shutdown,
causing a null pointer dereference in the async callback.
This commit is contained in:
2 * r + 2 * t 2026-03-24 01:52:44 +11:00
parent b85b0e7afb
commit d5c6e98126

View file

@ -75,13 +75,20 @@ void CUtils::saveItem(QQuickItem* target, const QUrl& path, const QRect& rect, Q
QObject::connect(watcher, &QFutureWatcher<bool>::finished, this, [=]() {
if (watcher->result()) {
if (onSaved.isCallable()) {
onSaved.call(
{ QJSValue(path.toLocalFile()), engine->toScriptValue(QVariant::fromValue(path)) });
QJSValueList args = { QJSValue(path.toLocalFile()) };
if (engine) {
args << engine->toScriptValue(QVariant::fromValue(path));
}
onSaved.call(args);
}
} else {
qWarning() << "CUtils::saveItem: failed to save" << path;
if (onFailed.isCallable()) {
onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) });
if (engine) {
onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) });
} else {
onFailed.call();
}
}
}
watcher->deleteLater();