Refactoring a huge mainwindow
-
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 -
Hi Matt,
refactor by extract Class method:
- Make the tabs / widgets / pages in the stack own classes.
Cheers
Gerolf -
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.
-
You can show your mainwindow.h? It will help for doing suggestions.
-
[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.