Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to modify project hierarchy ?
Qt 6.11 is out! See what's new in the release blog

How to modify project hierarchy ?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
5 Posts 2 Posters 1.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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    How to modify project hierarchy ?

    If I have a working project where I have

    class MdiChild : public QTextEdit

    I like to change the base class to QWidget AND keep the MdiChild code - where / how to ADD QWidget?

    Would multiple inheritance be OK ?
    or adding QWidget to QTextEdit as class variable be better ?

    class MdiChild : public QTextEdit, QWidget

    eventually the QWidget would be passed as a parameter to MdiChild...

    JKSHJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      How to modify project hierarchy ?

      If I have a working project where I have

      class MdiChild : public QTextEdit

      I like to change the base class to QWidget AND keep the MdiChild code - where / how to ADD QWidget?

      Would multiple inheritance be OK ?
      or adding QWidget to QTextEdit as class variable be better ?

      class MdiChild : public QTextEdit, QWidget

      eventually the QWidget would be passed as a parameter to MdiChild...

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

      @AnneRanch said in How to modify project hierarchy ?:

      If I have a working project where I have

      class MdiChild : public QTextEdit

      I like to change the base class to QWidget AND keep the MdiChild code - where / how to ADD QWidget?

      The most straightforward way to do this is to change the inheritance to

      class MdiChild : public QWidget

      Of course, if your project currently calls QTextEdit functions on your MdiChild, then you'll need to move more things around.

      Would multiple inheritance be OK ?

      class MdiChild : public QTextEdit, QWidget

      No, you cannot inherit from more than 1 QObject at a time: https://doc.qt.io/qt-5/moc.html#multiple-inheritance-requires-qobject-to-be-first

      or adding QWidget to QTextEdit as class variable be better ?

      Yes, quite often class variables ("composition") is better than inheritance: https://betterprogramming.pub/prefer-composition-over-inheritance-1602d5149ea1

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

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        OK, so if I can have only one QTObject as base class I should add QWidget as a plain QTWidget variable as class to MdiChild.
        And yes current MdiChild has ton of text file processing functions...I really do not need but may as well keep them.
        Since the QTWidget will be variable I cannot avoid to modify the original MdiChild and add QTWidget to it as a parameter.

        Is it feasible to overload the original MdiChild with such parameter ?

        JKSHJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          OK, so if I can have only one QTObject as base class I should add QWidget as a plain QTWidget variable as class to MdiChild.
          And yes current MdiChild has ton of text file processing functions...I really do not need but may as well keep them.
          Since the QTWidget will be variable I cannot avoid to modify the original MdiChild and add QTWidget to it as a parameter.

          Is it feasible to overload the original MdiChild with such parameter ?

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

          @AnneRanch said in How to modify project hierarchy ?:

          Since the QTWidget will be variable I cannot avoid to modify the original MdiChild and add QTWidget to it as a parameter.

          If you have a QWidget* member variable, then that variable can hold any kind of widget (QTextEdit, or QTableView, or something else).

          Is it feasible to overload the original MdiChild with such parameter ?

          I'm not completely sure what you mean here, but you can have different classes inherit your MdiChild class. Each of those different subclasses can do different things.

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            I may be looking at this wrong , but I have main class - MDIArea and Mdichild manages / displays etc. its "subclasses " - it does not inherits anything form MDIArea - just the opposite. In this example it inherits from "QTextEdit.

            Or should I say MdiChild t is based on QTextEdit ?

            One example - MdiChild manages "cascading" the MDIArea windows.
            It is this management I do not want to change - just "change: / add to" MdiChild class to include QTWidget - and adding it as a MDiChild variable seams to be the correct way.

            .

            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