my code:
//forkliftitem.h
class ForkliftItem : public QGraphicsObject
{
Q_OBJECT
//some necessary code...
}
//forkliftitem.cpp
ForkliftItem::ForkliftItem()
{
//some other code...
connect(this, &ForkliftItem::faceChanged, this, &ForkliftItem::setRotation);
}
When I compile my code will generate the error as shown in title.Certainly,
cannot convert argument 3 from 'const QGraphicsItem *' to 'const QObject *'
because QGraphicsItem *
is not inherited from QObject
.But my this
pointer's type is const ForkliftItem *
, and ForkliftItem
is inherited from QGraphicsObject
.
And compile information have the following tips:
see reference to function template instantiation 'QMetaObject::Connection QObject::connect<void(__thiscall ForkliftItem::* )(int),void(__thiscall QGraphicsItem::* )(qreal)>(const ForkliftItem *,Func1,const QGraphicsItem ,Func2,Qt::ConnectionType)' being compiled with [ Func1=void (__thiscall ForkliftItem:: )(int)
can be seen : argument 3 of connect()
is handled as const QGraphicsItem *
, that why generate the compile error.
I could repair the error by following code:
connect(this, &ForkliftItem::faceChanged, this,
static_cast<void (ForkliftItem::*) (qreal)>(&ForkliftItem::setRotation));
But I feel very confused by that const ForkliftItem *
became const QGraphicsItem *
when call connect(this, fun1, this, fun2)
, and argument 1 is used correctly and argument 3 not.Anybody knows, please tell me, thanks.
ForkliftItem::faceChanged
? – G.M.