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, [=]() {
|
QObject::connect(watcher, &QFutureWatcher<bool>::finished, this, [=]() {
|
||||||
if (watcher->result()) {
|
if (watcher->result()) {
|
||||||
if (onSaved.isCallable()) {
|
if (onSaved.isCallable()) {
|
||||||
onSaved.call(
|
QJSValueList args = { QJSValue(path.toLocalFile()) };
|
||||||
{ QJSValue(path.toLocalFile()), engine->toScriptValue(QVariant::fromValue(path)) });
|
if (engine) {
|
||||||
|
args << engine->toScriptValue(QVariant::fromValue(path));
|
||||||
|
}
|
||||||
|
onSaved.call(args);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "CUtils::saveItem: failed to save" << path;
|
qWarning() << "CUtils::saveItem: failed to save" << path;
|
||||||
if (onFailed.isCallable()) {
|
if (onFailed.isCallable()) {
|
||||||
|
if (engine) {
|
||||||
onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) });
|
onFailed.call({ engine->toScriptValue(QVariant::fromValue(path)) });
|
||||||
|
} else {
|
||||||
|
onFailed.call();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
watcher->deleteLater();
|
watcher->deleteLater();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue