C++ GUI Challenge - c++

Recently I was challenged by a friend to create a snake game much like the classic Nokia version using the C++ language.
I have been programming in Java, but unlike Java, C++ doesn't seem to have standard gui libraries.
Therefore after looking into GUI for C++ many different api are available.
Which one would be best for this task?
I use Linux, so something that is cross platform with Windows would be beneficial.

There are many GUI frameworks for C++, especially Qt. You can also use GTK+ for Linux, or wxWidgets

As you mentioned there are several API and that comes down to opinion. I would suggest Qt. It is cross platform and I know many people use it.
http://www.qt.io/

I have been using FLTK (http://www.fltk.org/) as it's quite simple to use. Otherwise there are the below cross platform libs:
QT, wxWidget, GTK, CEGYUI (http://cegui.org.uk/), JUCE (http://www.juce.com/) to name a few.

As well as the truly graphical options like Qt, it is also worth considering a simpler one - ncurses. This essentially allows you to create GUI-like interfaces in a terminal and is supported on both Linux and Windows (via Cygwin/MinGW).
This is an example that I made back in university during the summer after a C programming module. It's quite simple graphics wise, but it is a fully functioning snake game.

Related

Writing C (and variations) on a Mac, and Exporting to Mac AND Windows

So I was just told that it's not the easiest thing to write an Objective C program on a mac using xcode that can also be run in windows (because xcode utilizes mac-exclusive libraries).
I'm not too picky about the language I use because I'm just learning, so is there an easy way to program C/C#/C++/Objective C on a mac that can be (easily) exported and run in Windows?
You can compile Objective-C code for Windows on a Mac using MXE. But I assume you're interested in GUI applications, not just pure, standard Objective-C code. In that case, you will need a cross-platform framework. For example Qt (MXE comes with Qt). But that's a C++ framework.
Objective-C for GUI applications is pretty much only used by Apple. If you want better portability of your applications, you should probably use C or C++. Python is another language you can use, if dynamic/scripted languages are your thing. Python also supports Qt, so you can write GUI apps with it.
The reason I recommend Qt over all other frameworks is that it doesn't just give you a GUI library, but it also gives you other classes that make it much easier to write cross-platform applications (for example an easy to use, Unicode string class, and classes for portable file I/O, networking, threading, etc.)
Look into cross-platform GUI libraries. Objective-C is largely associated with Apple products, so I doubt you'll find much cross-platform there.
For C#, the Mono project may be a good place to start:
http://www.mono-project.com/Main_Page
For C++, you can start by looking at Qt and Wx.
Depending on how much effort it is, you can also try separating out your GUI and trying to use some GUI scripting languages like Tk. This has the advantage that you'd have more leeway in your main language.

GUI for C++ newbie

With few years of experience with Java I decided it's time to take the time and learn C++. I just compiled and run my first C++ with eclipse (of course) and would like to take it one step fw - I wish to build a GUI.
Question: what GUIs are available to C++, something that is an open-source and runs on Mac and eclipse.
Some have mentioned Qt, some wxWidgets.
A quick rundown on crossplatform gui toolkits that you could try:
Qt: Looks appropriately native on whichever platform you use it on. It has its own build system however, which doesn't always like to play nicely with others. If you want the "beginners" experience in making a GUI with Qt, I recommend Qt Creator. It's a standalone IDE built by the developers of Qt.
wxWidgets: While Qt looks native (it tries its best to emulate the look and feel of the OS you are running on). wxWidgets is native. That is, it uses the GUI elements provided by the operating system. Last I looked at wxWidgets the C++ library was falling behind as far as modern development practices go. You are possibly more likely to learn bad programming habits from this library.
gtkmm: This is from the same guys who make the GIMP and Gnome, which as a MacOS user probably doesn't mean a lot to you. They don't try nearly as hard to fit in as wxWidgets and Qt. However, they probably have the most modern C++ library. They have done a lot of work to use modern C++ development practices. This can be helpful for a new programmer, as you are less likely to learn bad habits from them. On the downside, you'll get thrust into the land of templates and function pointers and such.
Those are the big ones with the most momentum behind them. There are countless others to also consider.
Use Qt
http://qt.nokia.com/products/
http://qt.nokia.com/products/eclipse-integration/
I'd recommend Qt which is open source, has an easy-to-use API with GUI designer, and can be used on many operating systems (Windows, Mac, Linux..) and looks native on whatever it's used on.
You might want to take a look at wxWidgets or Qt:
http://www.wxwidgets.org
http://qt.nokia.com/products/
More generally, see here:
http://en.wikipedia.org/wiki/List_of_widget_toolkits#Based_on_C_or_C.2B.2B_.28including_bindings_to_other_languages.29
I've personally used wxWidgets and found it to be quite good, if you're after a recommendation.

I'm developing GUI apps on Mac. I have been using C++ for 10+ years. Do I need to switch to Objective C?

I've been coding on C++/Linux for 10+ years.
I am switching to do Mac development.
My development involves GUI components.
Is my only choice to learn Cocoa/Objective-C, or is there a way to wrap Cocoa and use it from C++ land?
Thanks!
Yes, you need to learn Objective-C. Besides, you wouldn't gain much if you didn't need to. It's not the language that's hard to learn but the Cocoa framework (not because it's inherently hard but because it's so huge).
You could use Carbon, but that's deprecated.
As Ole says, Objective-C is not hard to learn if you have a C++ background - and you can mix the languages if you use Objective-C++ (which can be useful, but usually best to partition the code that uses different languages - so use Objective-C/ Cocoa for the GUI layer and C++ for the core logic. I do it this way in my iPhone game, vConqr).
If you've done GUI work in C++ I think you'll appreciate why Objective-C was chosen for Cocoa. It's very nice for event driven designs and has a number of abstractions that are a natural fit. As you get into more abstract areas, though, especially if you use a lot of containers and algorithms, you'll probably start to find the limitations a little annoying. But give it time - there are other useful abstractions that are not immediately obvious (dynamic typing, key/ value coding and other forms of reflection, categories...).
You might also find this stackoverflow question useful.
No, I don't think you need to learn Objective-C. You can use Qt framework to develop applications on Mac using C++.
If you are only going to work on Mac apps, then learn Objective-C and the Cocoa frameworks. Cocoa apps can pick up new features "for free" in newer Mac OS X releases, and will be more future-proof than a cross-platform app framework like Qt.
There are so many aspects to Cocoa frameworks (collectively) that you would be best served by sticking to the native app framework to serve your customers (end users). That is really what matters, not the short term inconvenience of learning a new language or framework (which comes with the job, adapt or die).
Pretty soon you will be as frustrated with Xcode as the rest of us.
I use WxWindows on the Mac for my tool development. Took a little bit of working but I got my Jam based c++ pipeline that I use on windows working perfectly. The only thing you need to remember to get it all correctly working is to create the proper application rules... easy to get working as a jam rule.
As mentioned in a few of the other answers, there are a number of cross platform GUI libraries that support mac. Such as Qt and WxWindows. You can use any of them, I personally have only used Qt and found it quite pleasurable to work with after coming from Java and C toolkits.
In order to use the native GUI libraries, you can use Python as well (PyObjC). Java is also able to make native looking apps in OS X.

Should a person new to windowed applications study X, GTK+, or what?

Let's say the factors for valuing a choice are the library of widgets available, the slope of the learning curve, and the degree of portability (platforms it works on). As far a language binding goes, I'm using C++.
Thanks!
Pure X is quite hardcore these days, and not very portable. Basically, there are three major toolkits:
GTK+ (and C++ wrapper GTKmm)
Qt
wxWidgets
which are pretty comparable, so which to choose is a matter of taste. All three run on major three operating systems, although GTK+ on Mac and Windows is little bit awkward.
Qt is very good. It has quite large library (not UI only). Runs on a lot of platforms.
My personal favorite: Qt. It's cross-platform, it's very intuitive, it's extensively documented, there's bindings for many languages (the original is C++), and it's actually fun to develop with it.
Unless you're planning to write your own UI toolkit, there's really no point in using X directly anymore. Too hard, too much work.
On Linux, you have the two main choices - GTK and Qt. Both work fine. Qt works better as a native C++ toolkit than GTK itself, although GTKmm is a decent C++ wrapper for it. GTK tends to be usable from more languages than Qt, but that doesn't matter if you're using C++ anyway.
Both are cross-platform, but GTK feels somewhat alien on other operating systems, particularly on Mac OS X. Qt feels completely native on Windows, and fairly close on Mac OS X. It also provides a lot of other cross-platform functionality beyond the UI, such as threading, filesystem access, networking, and so on. Qt certainly seems to win on the portability front, at least.
Generally, go with something that's popular - there's more chance of finding good examples, pre-made applications you can dissect, libraries you can use, or even just finding help here.
As you requested a widget library for C++, then I would suggest QT, which was created for that programming language; GTK is good too, but it was created for C (as many of the libraries created for the GNU project which privileges C against C++).
Nobody uses X directly while creating an application; the only people who work directly with X is who is creating a new widget library, as already reported from other people here.
GTK+ it is: runs on most Linux distros and Windows too.
Of course there are also Qt and WxWidgets which are cross-platform.
In my opinion, the best C++ GUI toolkit is Qt http://qt.nokia.com
It's cross-plateform (windows, mac os x, linux), efficient and has quite a few nice extensions (Qwt, Qwt3d, QGLViewer, ...)
On the other hand, if you want to learn about GUI programming, I would learn quite a few systems, including GTK, Tk, Motif.
I suggest getting a generic book on GUIs. I have used Borland's, Windows, wxWidgets, QT, and PEG windowing frameworks. In summary, there is no standard, but GUI systems are Event Driven. Study up on Event Driven programming and that should give you an excellent foundation.
I think you can start with wxWidgets.
If you are most familiar with an interested in C, GTK+ is a good place to start. If C++, QT is probably a better choice. Your desktop of choice is also a factor. Gnome uses GTK+, KDE uses QT.
Raw X programming is much to low-level to start with. Very few programs are written directly against the X API directly. There have always been toolkits layered over it. Some of the older toolkits are Motif (Lesstif) and Athena. Don't try to start with those though, they are very old now.
I think there is another issue that you did not mention: where do you want to go with it?
do you want to "just learn it" or do you have a specific application in mind?
if you have an application, perhaps you also need to consider:
what OS you plan to run it on
how is the community supporting it: active? is it difficult to get help?
what performance do you need/expect?
how long do you plan to support it? (you might decide to run^H^H^Hmove away from C++ in a few years, and if so, would it make sense to use a different language - ie Java?)

Should I use a cross-platform GUI-toolkit or rely on the native ones?

On my side job as programmer, I am to write a program in C++ to convert audio files from/to various formats. Probably, this will involve building a simple GUI.
Will it be a great effort to build seperate GUIs for Mac and Windows using Cocoa and WinForms instead of a cross-platform toolkit like Qt or GTK? (I will have to maintain a seperate Windows-version and Mac-Version anyway)
The GUI will probably be very simple and only need very basic functionality.
I always felt that native GUIs feel far more intuitive than its cross-platform brethren...
If you have the expertise, use native frontends, it'll effectively double the job you have to do for UI but from my experience non-native UI is a little bit clunkier than their native counterparts.
Have you looked at wxWidgets? Cross platform native controls.
I would agree that if possible, native front-ends are the way to go. I've not used wxWidgets recently, and I've heard it's come a long way, but back when it was wxWindows, we built an app with it that was spec'd to be built in X/Motif. When we finished the effort and delivered it, the customer said it did not look enough like X/Motif, and we had to re-work the entire UI at our expense... Joel Spolsky wrote a good article on this, but I can't remember the title. What he did say, IIRC, was the problem with Java and some other cross-platform UI was that "your dog barks at my app" - it's the little inconsistencies that annoy folks.
Cross-platform toolkits, more or less, all make the incorrect assumption that the difference between platforms is a matter of button placement and widget styling. In some cases you can get away with this - a Qt app will feel fairly native on both Windows (where UI conventions are very lax) and on Linux, particularly a KDE environment. In general, you can move between Linux and Windows relatively easily; conventions are similar, and the Windows community is lax about them.
Mac is the hard one. Its UI is built around an entirely different paradigm than either Windows or most Linux environments.
But in general, in a native app it's easier to speak the native language of the platform in more ways than just widget style.
Yes.
But seriously, it depends on your goals. I agree that the native UI libraries, with a bunch of effort put into them, will give vastly better results, but for lots of apps, a very basic UI is sufficient and a lot less effort if you take one of the existing cross platform frameworks.
Maybe starting with the CLI and getting functionality working makes the most sense for an audio conversion application.
I'm going to write my own cross platform application GUI layer for this soon.
Depending on the complexity of your application this can be a fraction of what is required for QT, GTK or FOX.
Reason is that we see a tendency that the platform vendors (Apple first) tries to design there system so that it looks unique. This makes it much harder for QT, GTK, FOX and other platform tools to constantly keep in sync with the latest widgets.
When the underlaying technique becomes more and more the same the OS vendors have no option then branding on look and feel of the platform.
wxWidgets used standard c++ syntax and preprocessor thus make you easily alter from plain C or C++. And will produce very native look where is appear, be it on GTK, X11, MS-Windows or Mac.
It's mature since 20yrs of 1rst release, has complete documentation with easy navigating, and supported by large community arround the world.
Coding in your favorite IDE or use prominent Eclipse-IDE and wxFormBuilder as GUI designer. Build wx library and IDE/Toolchain setup could be found on this link: http://yasriady.blogspot.co.id/2016/01/raspberry-pi-toolchain.html
Develop your application in Linux desktop and also provided compiler for Raspberry Pi2 (target application tested work smootly on Raspbian Jessie) ............