Results 1 to 6 of 6

Thread: qobject_cast vs dynamic_cast

  1. #1
    Join Date
    Feb 2009
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default qobject_cast vs dynamic_cast

    Hi,
    Does anyone have an idea of the performance difference between a qobject_cast and a dynamic_cast? My understanding of dynamic_cast is that it's slow, and that the amount of time taken depends on the complexity of your object heirarchy, and whether you're upcasting, downcasting etc..
    How does this compare with qobject_cast? Also i see that it doesn't require RTTI, so does Qt just emulate RTTI in its meta-object system?

    Thanks,
    mike

  2. #2
    Join Date
    Apr 2010
    Location
    Minsk, Republic of Belarus
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qobject_cast vs dynamic_cast

    If you import c++ class from dynamic link library dynamic_cast not worked. I have not had time to try qobject_cast, but think that it worked.

  3. #3
    Join Date
    Feb 2009
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qobject_cast vs dynamic_cast

    thanks, however i'm particularly interested in the performance difference (rather than the 'features' of one cast vs another).
    and also, how does a qobject_cast resolve internally without RTTI?

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: qobject_cast vs dynamic_cast

    qobject_cast is generally faster and it uses Qt's meta object system.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qobject_cast vs dynamic_cast

    Quote Originally Posted by mike_c View Post
    and also, how does a qobject_cast resolve internally without RTTI?
    So you are into features after all

    qobject_cast speed will also depend on the inheritance tree complexity but it only checks QObject inheritance so that's a "straight line" instead of a tree.

  6. #6
    Join Date
    Apr 2010
    Location
    Minsk, Republic of Belarus
    Posts
    19
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qobject_cast vs dynamic_cast

    qobject_cast also casts Q_INTERFACES branch.

Similar Threads

  1. dynamic_cast problems with custom widgets
    By jftaylor21 in forum Qt Programming
    Replies: 6
    Last Post: 19th February 2010, 14:59
  2. dynamic_cast not working
    By kloffy in forum Newbie
    Replies: 2
    Last Post: 11th October 2007, 23:07
  3. dynamic_cast and templates
    By KShots in forum General Programming
    Replies: 7
    Last Post: 7th August 2007, 20:01
  4. Why can't I make dynamic_cast work properly?
    By pir in forum General Programming
    Replies: 13
    Last Post: 18th July 2006, 16:17
  5. Problem with dynamic_cast
    By vratojr in forum General Programming
    Replies: 7
    Last Post: 12th April 2006, 13:45

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.