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. Explain "subclass"
Forum Updated to NodeBB v4.3 + New Features

Explain "subclass"

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 1.9k Views 3 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by
    #1

    I have done a significant amount of C++ programming, but only with basic classes and mostly procedural code. Now I am following examples in the book: “C++ GUI Programming with QT 4” and find word “subclass.” Searching on that, a Stackoverflow thread said there is no such thing as “subclass.” I presume that is a purist view and while they seem to have a point I find subclass used in the book and in my installed QT documentation. The book instructs the reader to create a dot h file with this:

    Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

    Is this a subclass of Qdialog and of Ui::GotoCellDialog?
    I keep this short by positing no further and asking:
    What is the concept of subclass? I presume the above is an example. Please tell me how to read it.

    raven-worxR JonBJ 2 Replies Last reply
    0
    • B BKBK

      I have done a significant amount of C++ programming, but only with basic classes and mostly procedural code. Now I am following examples in the book: “C++ GUI Programming with QT 4” and find word “subclass.” Searching on that, a Stackoverflow thread said there is no such thing as “subclass.” I presume that is a purist view and while they seem to have a point I find subclass used in the book and in my installed QT documentation. The book instructs the reader to create a dot h file with this:

      Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

      Is this a subclass of Qdialog and of Ui::GotoCellDialog?
      I keep this short by positing no further and asking:
      What is the concept of subclass? I presume the above is an example. Please tell me how to read it.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @BKBK said in Explain "subclass":

      Is this a subclass of Qdialog and of Ui::GotoCellDialog?

      i would say so. Actually IMO subclass is a common term in programming?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      O 1 Reply Last reply
      1
      • B BKBK

        I have done a significant amount of C++ programming, but only with basic classes and mostly procedural code. Now I am following examples in the book: “C++ GUI Programming with QT 4” and find word “subclass.” Searching on that, a Stackoverflow thread said there is no such thing as “subclass.” I presume that is a purist view and while they seem to have a point I find subclass used in the book and in my installed QT documentation. The book instructs the reader to create a dot h file with this:

        Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

        Is this a subclass of Qdialog and of Ui::GotoCellDialog?
        I keep this short by positing no further and asking:
        What is the concept of subclass? I presume the above is an example. Please tell me how to read it.

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

        @BKBK
        Just to say: I don't blame you for asking about your example! But since you say you are starting out (you have done classes, but not sob-classes, which seems a little odd, but never mind), you have enough to absorb if you can just stick to classes which only sub-class (or "inherit", you'll see that too) from one other class. Most (but not all) Qt classes are sub-classes of one other class, up a chain.

        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @BKBK said in Explain "subclass":

          Is this a subclass of Qdialog and of Ui::GotoCellDialog?

          i would say so. Actually IMO subclass is a common term in programming?!

          O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          @raven-worx Smalltalk used the term subclass, while C++ uses the term derived class. In the Smalltalk development environment, you started with a class, the superclass, and defined a class, the subclass, that inherited all of the behavior (methods, which are C++ member functions) and variables of the superclass. You then added variables and behavior to differentiate (specialize) the subclass from the superclass.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BKBK
            wrote on last edited by
            #5

            Wow, thanks. I did real time telemetry work using Visual Studio and C++. The classes helped out quite a bit but the basic processing was conceptually simple so I did not go deep. It was really plain C with some classes for significant convenience. Back to today: I read this:

            Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

            As: Create a class named GoToCellDialog that inherits from Qdialog and make the public attributes/methods/etc that are in QDialog, public within this new class. Understand that, hopefully.

            Now it becomes opaque, for me. The book specifically has the reader name the form: GoToCellDialog. I see that is important. I don’t know how to read that phrase: “…, public Ui::GoToCallDialog…”
            I did visit the on-line documentation but was unable to fully understand it.
            Thanks for your time and patience.

            JKSHJ 1 Reply Last reply
            0
            • B BKBK

              Wow, thanks. I did real time telemetry work using Visual Studio and C++. The classes helped out quite a bit but the basic processing was conceptually simple so I did not go deep. It was really plain C with some classes for significant convenience. Back to today: I read this:

              Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

              As: Create a class named GoToCellDialog that inherits from Qdialog and make the public attributes/methods/etc that are in QDialog, public within this new class. Understand that, hopefully.

              Now it becomes opaque, for me. The book specifically has the reader name the form: GoToCellDialog. I see that is important. I don’t know how to read that phrase: “…, public Ui::GoToCallDialog…”
              I did visit the on-line documentation but was unable to fully understand it.
              Thanks for your time and patience.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #6

              @BKBK said in Explain "subclass":

              Class GoToCellDialog : public Qdialog, public Ui::GoToCellDialog { Q_OBJECT … }

              As: Create a class named GoToCellDialog that inherits from Qdialog and make the public attributes/methods/etc that are in QDialog, public within this new class. Understand that, hopefully.

              Now it becomes opaque, for me. The book specifically has the reader name the form: GoToCellDialog. I see that is important. I don’t know how to read that phrase: “…, public Ui::GoToCallDialog…”

              You're partially correct.

              The code actually means, create a class named GoToCellDialog that publicly inherits from two other classes:

              • QDialog
              • Ui::GoToCellDialog

              Deriving from 2 (or more) classes is called multiple inheritance.

              The least obvious part is probably this: There are two different and separate classes called "GoToCellDialog" in this example!

              1. GoToCellDialog is a class called "GoToCellDialog" in the global namespace
              2. Ui::GoToCellDialog is a class called "GoToCellDialog" in the Ui namespace Ui.

              Class 1 inherits from Class 2.

              Ui and Ui::GoToCellDialog are auto-generated by Qt Creator when you create a Qt Designer form for GoToCellDialog.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              3

              • Login

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