lundi 24 avril 2023

Qt Best Practices with Widgets & UI forms

This is my first time using Qt, and also my first time using it for a relatively serious project. I understand that writing Qt code is a bit different from writing plain C++ due to the nature of the problem space. I believe I have a good grasp of signals & slots and general library, as well as QtCreator. I've reviewed a number of tutorials, documentations, and GitHub projects with no clear answer to my question, at least without digging into one of said projects (which are quite large and therefore hard to question code design use cases), assuming they are well designed.

My question is how to widgets are modularized (and ui forms, presumably) into their own files; I am aware that a ui_mainwindow.h file is generated from mainwindow.ui, and contains the (global) widget objects/variables which you can access from MainWindow.cpp, however I am at a bit of a loss as to how to you would go about putting those widget objects into their own files and/or classes, therefore encapsulating them e.g.:

MainWindow.cpp
MainWindow.h
Button.cpp
Button.hpp
Search.cpp
Search.hpp
ListView.cpp
ListView.hpp

There is the option of creating everything programmatically which I have seen projects do; RPCS3 by contrast only seems to use new ui forms for separate pages/menus. I would however like to keep presentation and logic separate, but am not sure how to go about it without having a single bloated MainWindow.cpp file.

Aucun commentaire:

Enregistrer un commentaire