I have two different custom QGraphicsScene presented by means of two different QGraphicsView. I want to drag and drop items from one scene to another. Therefore I have implemented following in my QGraphicsScene:

void mousePressEvent
void mouseMoveEvent
void dragEnterEvent
void dragMoveEvent
void dragLeaveEvent
void dropEvent


I want to reject drop; if it is same Scene I am dragging from and dropping into. For this; I need to get QGraphicsSceneDragDropEvent::event->source() and cast it to a proper widget and see if it has originated from the same object by comparing it with 'this' pointer.


void my_Chart::dragEnterEvent(QGraphicsSceneDragDropEve nt *event)
{
my_Chart *chart= qobject_cast<my_Chart *> (event->source());
if(chart != 0)
{
if(chart != this)
// do something relevent
else
//reject drop
}
else
{
//reject drop
}

}

The casting is always failing, whatever I do. Chart is always 0. I have checked documentation, It says that:http://doc.qt.io/qt-5/qgraphicsscene...nt.html#source
This function returns the QGraphicsView that created the QGraphicsSceneDragDropEvent. So I tried:

my_ChartView *chart= qobject_cast<my_ChartView *> (event->source());

But this also failed. Kindly help.