PDA

View Full Version : QGraphicsItem: pure virtual method call problem



phuongot
17th January 2012, 03:16
Hi every body,
Please help me with this problem:
I have a class TrackObject that derived from QgsmapcanvasItem to draw a dynamic object on Map, the QgsMapcanvasItem is derived from QGraphicsItem. sometimes i get a pure virtual method call exception and the program is crashed. the "pure virtual method call" exception occured when i create a new TrackObject or delete the TrackObject. I use QGis for MAP and QT version 4.7.4 on OpenSuse OS.

the attachment is my exception.

Thanks in advance!

pkj
17th January 2012, 04:14
Pure virtual if directly or indirectly called from base class constructor or destructor causes such messages. While direct calling causes linking failure in gcc4.x, indirect calling is not detected and leads to crash.

ChrisW67
17th January 2012, 04:33
Are you calling virtual methods in the constructors or destructor of the TrackObject class?

Edit: beaten to it.

phuongot
17th January 2012, 05:33
Are you calling virtual methods in the constructors or destructor of the TrackObject class?

Edit: beaten to it.

I sure that i did not call any virtual methods in my constructors or destructors.

here is my constructor, i only initialized some properties:


TrackObject::TrackObject(QgsMapCanvas* canvas) : QgsMapCanvasItem(canvas)
{
mSize = 16;
trackInfo = NULL;
heading = 0;
speed = 0;
fColor = QColor(0, 0, 0);
mLastReceiveTime = time(NULL);
bActive = false;
bDrawHeading = true;
nOnwFligh = 0;
textPosition = 0;
nBateryId = 0;
targetStatus = FilterUnknown;
nTrackID = -1;
nTrackNumber = -1;
isDisplaying = true;
setFlag(ItemIsMovable);
}

and the destructor, just delete the trackinfo object. the TrackInfo object store some information about the coordinate (lontitude, latitude,..) and also not call any virtual function in its destructor:


TrackObject::~TrackObject()
{
if(trackInfo)
{
delete trackInfo;
trackInfo = NULL;
}
}

the application not crashed immediately when started but it only run within about 15 - 30 mins after some create and delete TrackObject times.

ChrisW67
17th January 2012, 07:03
What is QgsMapCanvasItem::QgsMapCanvasItem() and setFlag() doing?

phuongot
17th January 2012, 07:35
What is QgsMapCanvasItem::QgsMapCanvasItem() and setFlag() doing?

Hi ChrisW67,

The QgsMapCanvasItem is a class of QGis library. you can see the constructor of QgsMapcanvasItem here:http://qgis.org/api/qgsmapcanvasitem_8cpp-source.html. The setFlag is a member function of QGraphicsItem class: http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsitem.html#setFlag