PDA

View Full Version : mapToItem() question



Alex Brophy
16th April 2008, 16:00
Hi,
I'm trying to get the position of the origin point of a graphics item (myFirstItem) relative to another graphics item (mySecondItem) using Qt 4. From reading the documentation, it looks like mapToItem() should do this for me, specifically:

QPointF QGraphicsItem::mapToItem ( const QGraphicsItem * item, const QPointF & point ) const

I attempted to implement this as follows:



QPointF getRelativeOrigin(QGraphicsItem *myFirstItem, QGraphicsItem *mySecondItem)
{
QPointF *centrePoint;
QPointF relativePoint;

centrePoint = new QPointF(0.0, 0.0);
relativePoint = myFirstItem->mapToItem (mySecondItem, centrePoint);
return relativePoint;
}


It seems to assume a different interface to the method mapToItem() then I expect as the following errors are returned when I build:

demo.cpp: In member function ‘QPointF demo::getRelativeOrigin(QGraphicsItem*, QGraphicsItem*)’:
demo.cpp:146: error: invalid conversion from ‘QPointF*’ to ‘int’
demo.cpp:146: error: initializing argument 1 of ‘QPolygonF::QPolygonF(int)’
demo.cpp:146: error: no match for ‘operator=’ in ‘relativePoint = QGraphicsItem::mapToItem(const QGraphicsItem*, const QPolygonF&) const(((const QGraphicsItem*)mySecondItem), ((const QPolygonF&)(& QPolygonF(((int)centrePoint)))))’
/usr/local/Trolltech/Qt-4.3.4/include/QtCore/qpoint.h:190: note: candidates are: QPointF& QPointF::operator=(const QPointF&)

Can anyone suggest where I am going wrong?

wysota
16th April 2008, 16:38
The second argument is a const reference, not a pointer.


QPointF result = first->mapToItem(second, QPointF(0.0,0.0));

Alex Brophy
18th April 2008, 09:55
Thanks! That did the trick.