tags:

views:

1490

answers:

5

I am a C# programmer who started using ubuntu about 2 years ago. I'm wanting to learn GUI programming in either C or C++. I don't really like mono, it tends to crash on my system. I have a basic understanding of C++. I have never worked in C, but it looks cool. Which toolkit should I learn/use? Give Pro/Cons of each. Thanks!

+5  A: 

Since C++ is more familiar to you, you may find GTKmm to be a better fit, since you can use idioms like RAII. Unfortunately, GTKmm is a little incomplete and is missing a few of the lesser-used parts of GTK.

GTK+ on its own, however, essentially exposes an object model similar to what you find in C++, but with only C functions. Things like construction and destruction in C++ are done explicitly in the C API and instances of widgets are handled via pointers exclusively.

Try both and see which fits your project better.

greyfade
+1  A: 

Have you looked at QT?
It's nice C++ design, cross platform and LGPL

Martin Beckett
Yeah, I kinda like it but I don't (if that makes sense).
Lucas McCoy
Yeah I know what you mean. I mean not really
@Iraimbilanja: Nice One!
Lucas McCoy
But Honestly what I mean is I'm running ubuntu not kubuntu. So I'm using GNOME and not KDE. I tried Qt it doesn't exactly look right.
Lucas McCoy
Qt != KDEThings that "do not look rihgt" are theme-related. Try changing the Qt theme to get something eye-candy.
Anonymous
@Anonymous: I would rather it work right out of the box than have to change it. I'm lazy.
Lucas McCoy
If you really want to write gnomish apps, GTK is your only choice. There _is_ QGtkStyle acting as a bridge, but it's not the same. And in that case, GTKmm is much more sane. I don't wish for anyone to land in GObject hell.
The OP didn't say they wanted to wite gnome apps, they said gui apps. Gnome/GTK isn't the only choice
Martin Beckett
I disagree on the 'nice c++ design'. It abuses macros and gets in the way with other libs (boost::signals for example). Just as a side comment.
David Rodríguez - dribeas
You mean 'LGPL' meaning library or lesser GPL so you can link it with your propriety code and still keep it closed-source. (Same license as GTK)
Roalt
Well nice C++ compared to MFC! Sorry about the typo, I think all possible aconyms ending in L are now the name of some licence!
Martin Beckett
+4  A: 

I could be accused of bias since I do help contribute to gtkmm, but I was a user first, so... In any case, I would highly recommend gtkmm if you're comfortable with C++. Memory management is much easier with gtkmm than with GTK+ because reference-counted objects are managed automatically with smart pointers. You can also instantiate objects as auto variables (e.g. on the stack) and have their lifetime determined by their scope. So in practice, it's much easier to avoid memory leaks with gtkmm than with GTK+.

Another huge advantage of gtkmm over GTK+ (in my opinion) is the use of a type-safe signals framework. In GTK+, you constantly need to pass things as void pointers and then cast them around to the type you think they should be. In gtkmm, you dont need to do this, and can take advantage of the compiler enforcing type-safety on your signal handlers.

Another big advantage over C/GTK+ is the ease of deriving new classes. In GTK+, you need to write a lot of boilerplate code and basically re-implement things that you get for free in C++ as part of the language (e.g. inheritance, constructors, destructors, etc). This is more tedious and error-prone.

greyfade mentioned that gtkmm is incomplete, and he's right to a certain extent -- gtkmm does not cover absolutely everything in the GTK+ API (though it gets awfully close). But in practice this is not a problem because you can always use the C/GTK+ API directly from your gtkmm code. This C compatibility is a huge advantage of C++ over something like C# or python bindings where you would have no alternatives if the binding didn't cover part of the API.

The only real reasons to choose GTK+ over gtkmm (IMO) are that gtkmm has a little additional overhead since it is a wrapper on top of the C library (but this is generally just a single function call, which is going to have negligible impact), or if you hate or can't use C++.

jonner
+10  A: 

If you're a C# programmer, why don't you take a look at Vala?

I use pygtk for most of my Linux GUI applications, but Python was simply too slow for the project I'm working on right now, so I was trying to pick one of GTK+ and GTKmm. Then I met Vala.

It's a pretty new language, and therefore documentation is pretty limited at the moment, but I think it has the best of both worlds: C# syntax with C speed.

Can Berk Güder
Dude I'm total going to download this! Thanks, I may have just found my new language.
Lucas McCoy
You're welcome. I actually found out about Vala on SO myself. Cannot remember the exact question/answer though.
Can Berk Güder
+3  A: 

I would suggest to learn vala with gedit.

http://www.valaide.org/doku.php : vala

https://launchpad.net/valable : Eclipse

http://code.google.com/p/vtg/ : Gedit

http://abderrahim.arablug.org/blog/ : anjuta

plan9assembler
I learned vala and really liked it but the documentaion was horrible.
Lucas McCoy