QML Drag: Prevent crash when using image provider url
For attached property objects, qmlEngine will not return an engine. However, QQuickDragAttached's parent is the object to which it is attached, and from that one we can get the engine. Fixes: QTBUG-72045 Change-Id: I40748dd11ea3eb4604c37e932b2cfd3baad6fd1f Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
parent
cdf00b076e
commit
234dbbf255
|
@ -442,7 +442,7 @@ void QQuickDragAttached::setImageSource(const QUrl &url)
|
|||
if (url.isEmpty()) {
|
||||
d->pixmapLoader.clear();
|
||||
} else {
|
||||
d->pixmapLoader.load(qmlEngine(this), url);
|
||||
d->pixmapLoader.load(qmlEngine(parent()), url);
|
||||
}
|
||||
|
||||
Q_EMIT imageSourceChanged();
|
||||
|
|
|
@ -143,6 +143,7 @@ private slots:
|
|||
void source();
|
||||
void recursion_data();
|
||||
void recursion();
|
||||
void noCrashWithImageProvider();
|
||||
|
||||
private:
|
||||
QQmlEngine engine;
|
||||
|
@ -1279,6 +1280,30 @@ void tst_QQuickDrag::recursion()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QQuickDrag::noCrashWithImageProvider()
|
||||
{
|
||||
// QTBUG-72045
|
||||
QQmlComponent component(&engine);
|
||||
component.setData(
|
||||
R"(
|
||||
import QtQuick 2.9
|
||||
Item {
|
||||
Rectangle {
|
||||
id: item
|
||||
width: 50
|
||||
height: 50
|
||||
anchors.centerIn: parent
|
||||
color: "orange"
|
||||
Component.onCompleted: {
|
||||
item.Drag.imageSource = "image://kill/me"
|
||||
}
|
||||
}
|
||||
})", QUrl());
|
||||
QScopedPointer<QObject> object(component.create());
|
||||
QQuickItem *item = qobject_cast<QQuickItem *>(object.data());
|
||||
QVERIFY(item);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(tst_QQuickDrag)
|
||||
|
||||
|
|
Loading…
Reference in New Issue