tags:

views:

239

answers:

8

I always find good tutorials on the subject, but it almost always is C++. Is it hard or just doesn't make sense to make GUI applications with C?

A good book, guide or a tutorial is fine.

Platform: Linux

Thanks

A: 

Many high quality GUI were written in C with, for example, Windows API. There's no particular reason why not, but object oriented programming was very successful in modeling interactive graphics. GUI elements somehow map naturally into C++ objects that can encapsulate complex behavior behind a simple interface.

Pavel Radzivilovsky
+2  A: 

If you are programming in C on Windows - Petzold's programming windows used to be the bible for C based ui work.

EDIT: Since I answered my question the post has been updated to be on Linux. I will leave the post here for anybody looking, but it really does not apply to Linux.

Romain Hippeau
A: 

It's hard enough (or, mostly, verbose enough) that most people figure it just doesn't make sense. The GUI part of an application (mostly) reacts to user input, so in this area speed is rarely critical -- a difference of a few microseconds (or even milliseconds) rarely makes much difference. As long as responses appear within 100 ms (or so), they're pretty much perceived as "instant".

Dynamic typing also tends to work quite nicely for a lot of GUI programming. C uses only static typing.

Jerry Coffin
A: 

Don't.

Use python and then bind the computationally expensive calls written in C.

fabrizioM
A: 

If you're on a *nix system, you can use Xlib. But you're probably better off programming in C++ and calling out to your C code.

Stephen
+4  A: 

Use GTK+. It's written in C and exposes a well-designed C API. Their tutorial is quite excellent.

GTK+ is the toolkit for GNOME, so your applications will fit right in with many Linux desktops.

Michael E
A: 

What is the best way to design GUI Applications with C?

don't, if you don't have to :-)

Is it hard or just doesn't make sense to make GUI applications with C?

It is not necessarily that hard, but a pretty redundant and verbose task (like writing high level programs in assembly language), with lots of repeated boilerplate code.

Personally, I find it more rewarding to simply embed a scripting interpreter (e.g. Lua, Nasal) with bindings for a GUI library and then code the UI in a high level scripting language and code only the core of the application itself in C. Python was previously mentioned, but I think that a dedicated extension language like Lua would be a better fit, because it doesn't bloat your source code and because it does not create any additional requirements (like library dependencies or architectural).

In other words, embedding something like Python, Perl or Ruby may be relatively straight forward (because of good documentation and community momentum), but often these languages are more complex than the host application itself.

This is also the approach taken by the AlgoScore software, which uses an embedded Nasal interpreter with GTK bindings.

none
+3  A: 
  • nCurses library of old-school DOS-style GUIs in C.

  • GTK would be fine for a modern GUI.

  • Use Qt for a cross-platform tool to develop GUIs over win/Linux/mac/embedded/symbian

    http://qt.nokia.com/

CVS-2600Hertz
use wxWidgets, it's better than QT: www.wxwidgets.org
Quandary