Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Virtual functions always and forever virtual?
Forum Updated to NodeBB v4.3 + New Features

Virtual functions always and forever virtual?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 959 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stvokr
    wrote on last edited by
    #1

    Hi all,

    I have a general question concerning virtual functions. I think in Qt almost all destructors are virtual. QObject has a virtual destructor. But QWidget has no destructor which is explicitly defined as virtual in qwidget.h.

    • Is it necessary to define virtual functions of the base class also in my class as virtual?
    • Is a virtual function always virtual in every inherited class or is it possible to remove the virtual property?

    regards
    Oliver

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      You should ask such questions here: http://forum.qt.io/category/34/c-gurus
      since it is not related to Qt.

      You can omit "virtual" keyword in derived classes. And it is not necessary to define inherited virtual methods in derived classes, you only do this if you need a different behaviour or if it is a pure virtual method and you're going to instantiate your class.
      Methods (not functions) defined as virtual remain virtual.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stvokr
        wrote on last edited by
        #3

        Thanks.

        Oliver

        1 Reply Last reply
        0
        • TheBadgerT Offline
          TheBadgerT Offline
          TheBadger
          wrote on last edited by
          #4

          Look at https://en.wikipedia.org/wiki/C%2B%2B11#Explicit_overrides_and_final if you are using C++11


          Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved