Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Classes organisation - general good practices



  • Hi all, It's the first time I am coding a desktop application.
    I have a few questions about general good practices.
    I want to separate my main window in 3 subparts. On the left, I will have a QTableview. In the center, I will have a form with the details of the selected row of the left part, and on the right I will have a QDialogButtonBox related to the central part.

    I Am quite afraid to code the entire window in the cpp file for the main window as I think there will be a lot of widgets (so I think the file will be very long and maybe not easy to maintain). I am wondering how I should split it, and what should be a dedicated class.

    Is it a good idea to create a separate class for each part of the main window even though they will be connected with a dataMapper? Shall I put everything in a big file?

    Apart from that I will put everything that interacts with the database in a dedicated class.
    Any good practice recommendations to avoid having a unreadable code?

    Also on the database handling. Is it better to create big models that will hold the entire tables (I have 3 main tables) and then filter them out with a proxy model, or shall I create multiple individual lighter requests?

    Thank you
    Thombou


  • Lifetime Qt Champion

    Hi,

    Go with the usual: single responsibility. If a widget shall handle a particular aspect then keep it separated with a clean API so can also make it testable.

    For the models, it will highly depend on what you want to access and how you need to interact with it.


Log in to reply