I finished a project in C++
. It is a console application, created with CodeBlocks. Although I consider it not so important in the scope of this question: The application manages data about bills and customers of a small company. The program is complete and could be very easily expanded by a console user interface (right now, I run it as a programmer).
Now I decided to learn GUI programming using Qt
and the QtCreator with its QtDesigner!
Not only because it is common practice to separate logic from GUI when creating a GUI application, I want to put my project into practice in two big parts, namely, of course, logic and GUI.
You already know that the logic part is complete; what I have is a project folder called project
containing another folder (CodeBlocks project) project_logic
which again contains several classes, thus header files and implementation files (and a main, which will of course be obsolete, eventually). It also contains files from/into which the program reads/writes. It is written in "pure" C++
and uses none of the means provided by Qt
and it is important to me that it stays that way!
Now I added a Qt
project project_gui
into the project
-folder and started to create the GUI, implementing only the most basic functionality, like changing between dialogues, closing the application, etc. So far it knows nothing about its future back-end (project_logic
).
As a third component I need some kind of controlling which links the application's logic with its GUI. Here comes my conceptual question: What is the best way to put them together in one application?
Suggestions
Since
project_logic
could work alone as a console application, it already provides the most essential controlling components and functions. This will stay this way, because I want to keep its standalone functionality. Even more so because I am totally new to GUI programming and/or in two weeks I could happen to create another GUI for the same logic. The result would be that the classes of the logic part are included in the GUI source like any other header and used to create a program with full functionality. Validating user input would rest on the GUI part. The program's logic would in any case remain updatable.To make the GUI as reusable as possible; should I implement a third component à la
project_controlling
that provides interaction between GUI and logic (user input validation done by controlling) in that each of the two remain as independent as possible? GUI not including headers of logic, so to say, but including controlling headers?
The second point may sound a little bit weird, I admit; to put it short, my aims are:
- Keeping the
project_logic
standardC++
and independent (in terms of patching, adding functionality, etc...) and - using
Qt
for GUI at maximum (at the same time reasonable) separation of GUI and logic.
Trains of thoughts
Should I include the
project_logic
headers via#include "../project_logic/header1.h"
etc? (There may be a problem with using the classes, which I will post in a separate question.)Should I include them as a subproject?
How would I connect the parts "in code"?
Do the logic functions still find the files I mentioned earlier (read/write)?
Please keep the following in mind: I'm new to GUI programming! And I gave my best to explain my thoughts/problems... However, I know C and C++ and write console applications which I use for e.g. simulations at university and can handle the standard stuff quite well, I reckon. Even if the potential answerer feels like suggesting a very different approach, I would appreciate a "solution" for the concept I proposed. The reason for that I explained in the introduction. Unnecessary to mention though that I am of course interested in hearing different suggestions.
I decided to post the question after I did some research and tried my best in "trial & error" fashion before. There is a lot of information about this topic out there on StackOverflow and other boards, so I wanted to present my idea and collect criticism and inputs, rather than adding another "how to?" to the hodgepodge of questions.
Since this question is about the general approach, I will maybe (quite sure... :-P ) ask more technical questions later, which I would like to edit into this question (hyperlinks) as soon as they arise. However, basic recipes in this matter, if available, are welcomed, of course.
After some comments and answers I feel like posting a little EDIT just to make things clear:
Current status of logic
project_logic
is more or less finished and coded in CodeBlocks as a CodeBlocks project.- It could work as a console application with "console user interface". (It has a
main.cpp
which is now only used for debugging.) - Its components are divided in classes (headers and cpp implementation files) as much as possible.
Current status of GUI
project_gui
is being set up as a Qt-Widget-Application project (using QtCreator/Designer).- So far it is only GUI an nothing more (no connection to
project_logic
in any way).
Aims and ...
... the workflow, I want to follow, since this is my first big project:
project_logic
andproject_gui
won't leave their respective directories; they both are in a directory calledproject
. (Exception: Logic will be exported as a dll (or something similar) if necessary, which is then provided to the GUI.)- If there were things to be changed in the
project_logic
I want to do so in CodeBlocks (and repeat a possible export as described above). project_logic
(or any third layer like for instanceproject_controlling
) have to be made disposable forproject_gui
in the most easiest fashion imaginable... (see Trains of thoughts number 1) :-P