summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-06-27 10:02:03 +1000
committerQt by Nokia <qt-info@nokia.com>2012-06-27 04:24:18 +0200
commit46a58d283fb2bba254bab3c2a9859b55b3649c30 (patch)
treee12f8f229478453360e186d04bfce6426cef3e56 /src
parent5a8f7939f536096a3f512c8b1537e6bbe5f0269c (diff)
Item.mapFromItem() crashes with Items not created by the engine.
Item.mapFromItem() and Item.mapToItem() get the script engine from the item they are called on. Safer to use the script value passed to the function to determine the engine being used. Task-number: QTBUG-26280 Change-Id: Id72afd723b21ed0f1a747e2d802d6f9715f6c093 Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 86d4f6f7..ab14363c 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -2617,13 +2617,14 @@ void QDeclarativeItem::setKeepMouseGrab(bool keep)
*/
QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qreal y) const
{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
if (!itemObj && !item.isNull()) {
qmlInfo(this) << "mapFromItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
return 0;
}
+ QScriptValue sv = item.engine()->newObject();
+
// If QGraphicsItem::mapFromItem() is called with 0, behaves the same as mapFromScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapFromItem(itemObj, x, y);
sv.setProperty(QLatin1String("x"), p.x());
@@ -2654,13 +2655,14 @@ QScriptValue QDeclarativeItem::mapFromItem(const QScriptValue &item, qreal x, qr
*/
QScriptValue QDeclarativeItem::mapToItem(const QScriptValue &item, qreal x, qreal y) const
{
- QScriptValue sv = QDeclarativeEnginePrivate::getScriptEngine(qmlEngine(this))->newObject();
QDeclarativeItem *itemObj = qobject_cast<QDeclarativeItem*>(item.toQObject());
if (!itemObj && !item.isNull()) {
qmlInfo(this) << "mapToItem() given argument \"" << item.toString() << "\" which is neither null nor an Item";
return 0;
}
+ QScriptValue sv = item.engine()->newObject();
+
// If QGraphicsItem::mapToItem() is called with 0, behaves the same as mapToScene()
QPointF p = qobject_cast<QGraphicsItem*>(this)->mapToItem(itemObj, x, y);
sv.setProperty(QLatin1String("x"), p.x());