Results 1 to 4 of 4

Thread: Best way to cast QList of base class pointers to derived class pointers

Threaded View

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

    Default Re: Best way to cast QList of base class pointers to derived class pointers

    You will have to build a second list, casting each base class pointer to the derived class pointer, and discarding those that do not cast. If they are QGraphicsItem objects then you can use qgraphicsitem_cast. I would not use static_cast unless you can guarantee all the items in the scene are of the one type, and even then...

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

    wayfaerer (6th April 2012)

Similar Threads

  1. Replies: 2
    Last Post: 22nd November 2011, 05:19
  2. Replies: 8
    Last Post: 15th July 2010, 21:42
  3. Replies: 5
    Last Post: 20th April 2010, 17:48
  4. Can not cast into the derived class from QScrollBar
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2008, 10:23
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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
  •  
Qt is a trademark of The Qt Company.