Results 1 to 3 of 3

Thread: dynamic_cast on class inherit from QGraphicsItem

  1. #1
    Join Date
    Feb 2016
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default dynamic_cast on class inherit from QGraphicsItem

    Hello Guys, first i want sorry for my english
    I create class "Item", and that class inherit from QGraphicsItem.
    I use scene()->collidingItems(this) to detect collisions, i want to know what objects colide, and use metod frome that object. So i do something like this:

    QList<QGraphicsItem *> list;
    list = scene()->collidingItems(this);

    And now (please help me) how can I use metod from Item class, when list is QGraphiscItem? I try to use dynamic_cast, but i always get error "C2680: 'Item' : invalid target type for dynamic_cast target type must be a pointer or reference to a defined class" , maybe I do all wrong...
    I hope that You understand me

  2. #2
    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: dynamic_cast on class inherit from QGraphicsItem

    You might be missing the "*" in the cast type.
    Is it complaining on this?
    Qt Code:
    1. Item *i = dynamic_cast<Item*>(list.at(0));
    2. if (i) {
    3. // you have a pointer to an Item
    4. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    Rogagol (4th February 2016)

  4. #3
    Join Date
    Feb 2016
    Posts
    8
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: dynamic_cast on class inherit from QGraphicsItem

    Now it works!
    I was sure, that i tried with "*"
    Thx for qiuck reply.
    Last edited by Rogagol; 4th February 2016 at 23:39.

Similar Threads

  1. Replies: 5
    Last Post: 12th May 2014, 12:07
  2. Replies: 1
    Last Post: 22nd November 2013, 18:18
  3. Replies: 4
    Last Post: 29th December 2012, 22:01
  4. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 15:59
  5. Replies: 11
    Last Post: 6th March 2009, 23:15

Tags for this Thread

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.