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"
QtWS25 Last Chance

Explain "subclass"

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 1.8k Views
  • 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 30 Nov 2018, 17:05 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.

    R J 2 Replies Last reply 30 Nov 2018, 17:08
    0
    • B BKBK
      30 Nov 2018, 17:05

      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.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 30 Nov 2018, 17:08 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 30 Nov 2018, 17:19
      1
      • B BKBK
        30 Nov 2018, 17:05

        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.

        J Online
        J Online
        JonB
        wrote on 30 Nov 2018, 17:12 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
        • R raven-worx
          30 Nov 2018, 17:08

          @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 30 Nov 2018, 17:19 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 30 Nov 2018, 18:04 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.

            J 1 Reply Last reply 1 Dec 2018, 11:20
            0
            • B BKBK
              30 Nov 2018, 18:04

              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.

              J Offline
              J Offline
              JKSH
              Moderators
              wrote on 1 Dec 2018, 11:20 last edited by JKSH 12 Jan 2018, 11:27
              #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

              1/6

              30 Nov 2018, 17:05

              • Login

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