Results 1 to 9 of 9

Thread: Why event functions in most cases are Protected and Virtual?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    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: Why event functions in most cases are Protected and Virtual?

    If you derive from a QObject, directly or through something else that does, then your class inherits all the virtual event handler functions. In your class declaration you can chose to use the 'virtual' keyword or not but the result is the same, the function will be virtual either way. That is:
    Qt Code:
    1. class Floober: public QObject {
    2. ...
    3. protected:
    4. virtual void childEvent ( QChildEvent * event );
    5. // is exactly the same as
    6. // void childEvent ( QChildEvent * event );
    7. ...
    8. };
    To copy to clipboard, switch view to plain text mode 
    Some people include "virtual" as an aide-mémoire to those who need to maintain the software later. I have seen claims that the ARM CC compiler issues a warning if the "virtual" is not present in derived classes: cannot vouch for that.

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

    blue_sky (24th March 2014)

Similar Threads

  1. C++ virtual functions
    By sonulohani in forum Newbie
    Replies: 3
    Last Post: 23rd May 2012, 09:17
  2. Virtual protected and private var
    By maddog_fr in forum Qt Programming
    Replies: 4
    Last Post: 19th November 2010, 16:14
  3. Problem with virtual functions
    By eekhoorn12 in forum General Programming
    Replies: 4
    Last Post: 8th April 2010, 13:52
  4. QSharedDataPointer and Data with virtual functions
    By niko in forum Qt Programming
    Replies: 0
    Last Post: 2nd February 2010, 08:23
  5. Replies: 10
    Last Post: 12th February 2007, 17:30

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.