GUI / Console Application Code Management (C ++ / Qt)

I am developing an application that should work as a GUI or console application. One mode at a time. When the application is compiled as a console, it should not use the GUI libraries. Since this is the first time I am doing such a thing, I would like to ask about traps, tips and tricks for such an event. Which approach would be best? Just use macros such as #define withGUI 1to switch? Or do something like a client / server solution?

+4
source share
2 answers

I would completely separate the business logic and graphical interface to stand-alone libraries - one for each. In the case of console application mode, I will refer to the only library that contains the logical part, and to both libraries. In doing so, you will not need to put # ifdef-s everywhere in your code and make reading difficult.

+2
source

There is a design template for this Model View Controller (MVC) . This separates the presentation of the data from the data model itself with the controller acting as a delegate and the control of updating the view with updates to the model.

Qt provides a similar system , but just uses a model and view.

. , , .

; , ( , ), . , , , .

+3

Source: https://habr.com/ru/post/1531577/


All Articles