Results 1 to 6 of 6

Thread: QGraphicsItem: pure virtual method call problem

  1. #1
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem: pure virtual method call problem

    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!
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem: pure virtual method call problem

    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.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGraphicsItem: pure virtual method call problem

    Are you calling virtual methods in the constructors or destructor of the TrackObject class?

    Edit: beaten to it.

  4. #4
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem: pure virtual method call problem

    Quote Originally Posted by ChrisW67 View Post
    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:
    Qt Code:
    1. TrackObject::TrackObject(QgsMapCanvas* canvas) : QgsMapCanvasItem(canvas)
    2. {
    3. mSize = 16;
    4. trackInfo = NULL;
    5. heading = 0;
    6. speed = 0;
    7. fColor = QColor(0, 0, 0);
    8. mLastReceiveTime = time(NULL);
    9. bActive = false;
    10. bDrawHeading = true;
    11. nOnwFligh = 0;
    12. textPosition = 0;
    13. nBateryId = 0;
    14. targetStatus = FilterUnknown;
    15. nTrackID = -1;
    16. nTrackNumber = -1;
    17. isDisplaying = true;
    18. setFlag(ItemIsMovable);
    19. }
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. TrackObject::~TrackObject()
    2. {
    3. if(trackInfo)
    4. {
    5. delete trackInfo;
    6. trackInfo = NULL;
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 
    the application not crashed immediately when started but it only run within about 15 - 30 mins after some create and delete TrackObject times.
    Last edited by phuongot; 17th January 2012 at 07:30.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QGraphicsItem: pure virtual method call problem

    What is QgsMapCanvasItem::QgsMapCanvasItem() and setFlag() doing?
    Last edited by ChrisW67; 17th January 2012 at 07:12.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  6. #6
    Join Date
    Jan 2012
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem: pure virtual method call problem

    Quote Originally Posted by ChrisW67 View Post
    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...m.html#setFlag

Similar Threads

  1. Replies: 2
    Last Post: 26th November 2011, 04:52
  2. the pure virtual method "abort" in QNetworkReply
    By mavenlin in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2011, 10:01
  3. Replies: 16
    Last Post: 13th March 2008, 17:46
  4. Cost of pure virtual
    By ShaChris23 in forum General Programming
    Replies: 4
    Last Post: 4th November 2007, 18:20
  5. inheritance, pure virtual
    By TheKedge in forum General Programming
    Replies: 2
    Last Post: 18th January 2007, 11:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.