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. Overriding a protected pure virtual function with a signal

Overriding a protected pure virtual function with a signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 7 Posters 5.1k Views 2 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #10

    Multiple inheritance with QObject could be problematic. When combining functionality with QObject classes I usually use composition rather than inheritance. I have run into issues with being able to copy objects based upon QObject. It also eliminates the use of templates for those classes. If I need a signal on an object that is not QObject based, and I can't or don't want to inherit from QObject. I will often create a subclass that gets created in the constructor and have it call methods on the parent object. I call this object a signal mule.

    C++ is a perfectly valid school of magic.

    M 1 Reply Last reply
    1
    • fcarneyF fcarney

      Multiple inheritance with QObject could be problematic. When combining functionality with QObject classes I usually use composition rather than inheritance. I have run into issues with being able to copy objects based upon QObject. It also eliminates the use of templates for those classes. If I need a signal on an object that is not QObject based, and I can't or don't want to inherit from QObject. I will often create a subclass that gets created in the constructor and have it call methods on the parent object. I call this object a signal mule.

      M Offline
      M Offline
      mooglus
      wrote on last edited by
      #11

      @fcarney Interesting reply. I've not run into trouble (yet) with multiple inheritance and Qt. Wouldn't you need to define an interface for your mule? That sounds like a bit of a hassle.

      JonBJ 1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #12

        @mooglus said in Overriding a protected pure virtual function with a signal:

        Wouldn't you need to define an interface for your mule?

        How would that be bad? If I need functionality I code that functionality.

        C++ is a perfectly valid school of magic.

        M 1 Reply Last reply
        0
        • fcarneyF fcarney

          @mooglus said in Overriding a protected pure virtual function with a signal:

          Wouldn't you need to define an interface for your mule?

          How would that be bad? If I need functionality I code that functionality.

          M Offline
          M Offline
          mooglus
          wrote on last edited by
          #13

          @fcarney It just seems like more typing to provide functionality that inheritance provides. However, if you're in a situation where inheritance is causing you problems then it makes sense. I've read many times that it's good to favour composition over inheritance, in practice I often find it inconvenient. I would upvote you, but your reputation is 666, I could never ruin that ;)

          fcarneyF Q 2 Replies Last reply
          1
          • M mooglus

            @fcarney It just seems like more typing to provide functionality that inheritance provides. However, if you're in a situation where inheritance is causing you problems then it makes sense. I've read many times that it's good to favour composition over inheritance, in practice I often find it inconvenient. I would upvote you, but your reputation is 666, I could never ruin that ;)

            fcarneyF Offline
            fcarneyF Offline
            fcarney
            wrote on last edited by
            #14

            @mooglus said in Overriding a protected pure virtual function with a signal:

            but your reputation is 666

            Makes sense. I use dark mode Qt Creator, makes me a haxor!

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            2
            • M mooglus

              @fcarney Interesting reply. I've not run into trouble (yet) with multiple inheritance and Qt. Wouldn't you need to define an interface for your mule? That sounds like a bit of a hassle.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #15

              @mooglus said in Overriding a protected pure virtual function with a signal:

              I've not run into trouble (yet) with multiple inheritance and Qt.

              If you do mean from QObject (perhaps you don't) then that is surprising. Inheriting from more than one QObject-derived class is problematic. There are various versions of Qt here, maybe things have changed over the years.

              https://stackoverflow.com/questions/8578657/qobject-multiple-inheritance/8578921
              https://www.ics.com/blog/multiple-inheritance-qt
              https://forum.qt.io/topic/88295/with-qt-5-6-is-it-possible-to-avoid-the-diamond-problem-when-signals-and-slots-are-defined-in-two-branches

              https://doc.qt.io/qt-5/moc.html#multiple-inheritance-requires-qobject-to-be-first

              If you are using multiple inheritance, moc assumes that the first inherited class is a subclass of QObject. Also, be sure that only the first inherited class is a QObject.

              1 Reply Last reply
              0
              • fcarneyF Offline
                fcarneyF Offline
                fcarney
                wrote on last edited by
                #16

                I wanted to inherit a templated class with a QObject. I ran into issues. Also multiple QObject inheritance doesn't work either.

                C++ is a perfectly valid school of magic.

                Christian EhrlicherC 1 Reply Last reply
                1
                • fcarneyF fcarney

                  I wanted to inherit a templated class with a QObject. I ran into issues. Also multiple QObject inheritance doesn't work either.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #17

                  @fcarney said in Overriding a protected pure virtual function with a signal:

                  I wanted to inherit a templated class with a QObject.

                  Works fine as long as you don't need moc stuff in the template

                  I ran into issues. Also multiple QObject inheritance doesn't work either.

                  Can not work to the parent-child relatonsship

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  kshegunovK 1 Reply Last reply
                  3
                  • Christian EhrlicherC Christian Ehrlicher

                    @fcarney said in Overriding a protected pure virtual function with a signal:

                    I wanted to inherit a templated class with a QObject.

                    Works fine as long as you don't need moc stuff in the template

                    I ran into issues. Also multiple QObject inheritance doesn't work either.

                    Can not work to the parent-child relatonsship

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #18

                    @Christian-Ehrlicher said in Overriding a protected pure virtual function with a signal:

                    Can not work to the parent-child relatonsship

                    Nor moc, more specifically it confuses the hell out of the meta-object system (e.g QMetaObject).

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • M mooglus

                      @fcarney It just seems like more typing to provide functionality that inheritance provides. However, if you're in a situation where inheritance is causing you problems then it makes sense. I've read many times that it's good to favour composition over inheritance, in practice I often find it inconvenient. I would upvote you, but your reputation is 666, I could never ruin that ;)

                      Q Offline
                      Q Offline
                      QtTester
                      wrote on last edited by QtTester
                      #19
                      This post is deleted!
                      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