Results 1 to 3 of 3

Thread: Why the destrcutors in some Qt abstract classes are not virtual?

  1. #1
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Question Why the destrcutors in some Qt abstract classes are not virtual?

    For example, in QAbstractItemModel.h, the destructor of class QAbstractItemModel is virtual, while the destructor of class QAbstractTableModel and QAbstractListModel are not virtual?
    I use Qt library V4.6.2.

  2. #2
    Join Date
    May 2008
    Location
    Kyiv, Ukraine
    Posts
    418
    Thanks
    1
    Thanked 29 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Why the destrcutors in some Qt abstract classes are not virtual?

    There is no keyword 'virtual' but the destructors are virtual, because these classes inherit QAbstractItemModel whose destructor is virtual.

    Consider this code:
    Qt Code:
    1. class Base
    2. {
    3. public:
    4. virtual void f() { std::cout << "Base::f" << std::endl; }
    5. };
    6.  
    7. class Derived : public Base
    8. {
    9. public:
    10. void f() { std::cout << "Derived::f" << std::endl; }
    11.  
    12. };
    13.  
    14. int main(int argc, char **argv)
    15. {
    16. Base *base = new Derived();
    17. base->f();
    18. }
    To copy to clipboard, switch view to plain text mode 

    You'll get "Derived::f" printed. At least I'm getting this result .
    I'm a rebel in the S.D.G.

  3. #3
    Join Date
    Sep 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why the destrcutors in some Qt abstract classes are not virtual?

    Yes. I got it. Thank you, lyuts!

Similar Threads

  1. Abstract threading
    By TheJim01 in forum Newbie
    Replies: 15
    Last Post: 14th April 2010, 21:46
  2. Abstract signals?
    By TorAn in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2010, 19:31
  3. Choice between Standard- and Abstract Item Model
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2009, 15:14
  4. Quick question regarding abstract classes and DLLs
    By durbrak in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2007, 21:32
  5. abstract scroll area
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 09:15

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.