By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,068 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,068 IT Pros & Developers. It's quick & easy.

How To Add A GUI To A C++ Program

P: 1
Hi all,

I'm a third year CS student. In all my classes, I have only every made programs that have worked via the command line. I'm starting on a personal project that involves creating a program for sports tournaments such as seeding players, displaying stats, etc.

My major questions are:

1). Can I code my program as a simple command line based program, then integrate the GUI after? Or should I implement my program with the GUI the first time around.

2). I've looked into how GUIs can be implemented and want to try wxWidgets. Is this a good idea?

3). Should I use a different language? I've read that GUIs are hard to implement via C++. I have only learned C++, C, and Python, but am not against learning new languages!

4). Are there any good guides that you can recommend to me?

Any and all help are appreciated! Thank you! :D
2 Weeks Ago #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 260
Stream objects are used to accept or display data to the console. Similarly, objects are used with getter and setter methods to display data from/to the GUI. Internal processing remains the same. It's just how the data is moved to and from the methods accordingly keeping in mind the principles of OOP.
2 Weeks Ago #2

Expert Mod 5K+
P: 8,950
More formally you should keep your business logic and user interface separate.

Take a simple example, calculate the area of a triangle given it's side lengths. You can just write a console program that does that, but if later you want a GUI program to do it you would have to re-implement the algorithm.

OK so not much of an issue for this simple a formula but for a more complex problem, especially if you have had to test to make sure you get the right results then you not only have to re-implement but re-test everything.

To avoid that you encapsulate your logic in a reusable code unit, a class or a set of classes (or possibly if it's this simple a function). You can then test your reusable code to ensure correct operation. Then you can put whatever interface you want on-top of that code, console, GUI, web service etc.

GUI's are relatively easy to do in C++ (at least as easy as anything else) but pure C++ can't do it you have to add a platform; there are several platforms available but I would recommend Qt, it's what I use at work, it is as simple (or complex) as anything else, it has cross-platform support (Windows, Linux Mac, various mobile, various embedded), it has provenance (been around 25 years) and it is available free under an opensource license.

However there are others
wxWidgets - never used it, but also never heard anyone say anything nice about it
GTK - also never used it but it is widely used
Microsoft has something proprietary and I assume limited to Windows but don't know what it is (last time I used MS it was MFC but I do know they have moved on from that)
2 Weeks Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.