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:
parent
b85b0e7afb
commit
d5c6e98126
1 changed files with 10 additions and 3 deletions
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue