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. Refactoring a huge mainwindow
Forum Updated to NodeBB v4.3 + New Features

Refactoring a huge mainwindow

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.6k 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.
  • B Offline
    B Offline
    beefmusta
    wrote on last edited by
    #1

    My mainwindow.cpp file is getting incredibly large (32 slots and 1000+ lines so far) and although it's OK at the moment, I can see it getting a nightmare to maintain very soon. I was wondering if any Qt experts have any recommendations for how to go about refactoring large QMainWindow classes?

    Keep in mind I have other classes doing the backend work - the mainwindow class deals just with the GUI logic for talking to the backend objects so most of the methods are only a few lines. The problem is that it has a number of tab and stacked widget pages, and each of them has enough logic to be a small application in its own right. Any ideas on how to split this up nicely?

    Cheers,
    Matt

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi Matt,

      refactor by extract Class method:

      • Make the tabs / widgets / pages in the stack own classes.

      Cheers
      Gerolf

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beefmusta
        wrote on last edited by
        #3

        Thanks for the quick reply. The challenging part with that is going to be working out where best to make the extraction so as to have the least amount of coupling to the mainwindow, because there are quite a few dependencies. I'll give it a go.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          You can show your mainwindow.h? It will help for doing suggestions.

          --
          Vasiliy

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ivan.todorovich
            wrote on last edited by
            #5

            [quote author="Gerolf" date="1293054565"]Hi Matt,

            refactor by extract Class method:

            • Make the tabs / widgets / pages in the stack own classes.

            Cheers
            Gerolf[/quote]

            Agree. That's the best solution.
            I'm working on a similar project, where the MainWindow has at least 50 different pages. Most of them are similar (showing a list of customer, a list of suppliers, etc) so I have a QAbstractPage class, and I subclass for every different page.

            o_o Sorry for my rusted english.

            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