When to start a new .cpp .h .ui
-
Maybe a very basic question but I see so many tutorials based on just one function I am a little lost how to combine it all.
My main.cpp will have a nice top menu bar (file/edit/about etc)
Now inside this window I want to create a tabbed view. Easily done. But should I just create that in the main window.ui?
In each tab there is a different content
-tab 1 tableview from a database (different cpp?)
-tab 2 number overview from a database query etc
-tab 3 settings (store in a .ini/conf file)Database connection setting: different cpp?
-
@Seabird That's really up to you,
I've seen "Applications" where everything was in a 10k+ main.cpp
- was it readable? no
- did I throw up a little bit, when I saw it? yes, yes I did
As a general rule of thumb:
If you think: "Should I make this a separate class/file?" Than do it :D -
@J-Hilk said in When to start a new .cpp .h .ui:
where everything was in a 10k+ main.cpp
I know a user on this forum whose file is a lot bigger than this.... :)
@Seabird
Each of those tab contents sounds like a separate class/.ui
file to me. Don't forget you can design a widget in its own designer file/.ui
file/.cpp
/.h
file, and then e.g. use that at runtime to create the desired pages for the tabs. -
@artwaw said in When to start a new .cpp .h .ui:
My rule of thumb is: can I make this bit of a code a separate, functional entity? If yes, then away it goes to a separate class.
The only thing I would say is. Some people create loads of little classes. And some people insist each class go in its own source file. Personally I find that "tiring" at the editing phase, having to swap between too many small classes/files. Not that yours isn't a reasonable rule, just one may not wish to take it too far down. There is a balance between classes/files which are too large and those which are too small.