8

I am choosing a GUI toolkit for C++ to learn. I have done some searching online and most people suggest GTKmm for C++ over GTK+. Despite that fact, I have seen some C++ applications made using GTK+.

Therefore, I just want to know the specific reasons for this:
1. Why GTKmm is preferred for C++?
2. What are the limitations I will face if I use GTK+ for C++ applications instead of GTKmm?

phongvcao
  • 479
  • 3
  • 10
  • 15
  • 1
    There are some great reasons on [its homepage](http://www.gtkmm.org/en/). – Josh Lee Apr 11 '11 at 03:04
  • Thanks for the quick reply! But is GTK+ able to do those? – phongvcao Apr 11 '11 at 03:07
  • If you are going to learn a GUI toolkit i'd much rather recommend Qt. Unless there is some feature GTK has that you need. – RedX Apr 13 '11 at 09:22
  • Well the only reason that I choose GTK+ (or Gtkmm) over Qt is because as far as I know most applications written in Qt looks pretty messy. I know that GTK looks foreign in windows & archaic in Mac, but I feel like applications using GTK are so much clearer in widgets arrangement comparing to the ones with Qt. The clearest Qt applications I have ever seen is VLC Media Player & QStardict. They look better than most of other Qt applications. – phongvcao Apr 14 '11 at 02:39
  • However, since I only develop software on Windows & Linux, I think Gtkmm is a good choice for me. If I am going to do any programming in Mac I will learn to use a GUI that is designed to be used in Mac. Although Qt can be used in OSX, sometimes it still looks very "foreign" – phongvcao Apr 14 '11 at 02:44
  • Be aware that despite the advertising, porting Gtk applications on Windows remains a significant challenge and you will find little support or documentation for it. So much that several software have migrated from Gtk to Qt : Subsurface, Wireshark, GCompris. Even Gimp is true challenge to compile on Windows. That's unlike Qt who works by design on all 3 major platforms, with very strong support. – Philippe F Dec 03 '19 at 08:50

1 Answers1

22
  • gtkmm allows you to write code using normal C++ techniques such as encapsulation, derivation, and polymorphism. As a C++ programmer you probably already realize that this leads to clearer and better organised code.
  • gtkmm is more type-safe, so the compiler can detect errors that would only be detected at run time when using C. This use of specific types also makes the API clearer because you can see what types should be used just by looking at a method's declaration.
  • Inheritance can be used to derive new widgets. The derivation of new widgets in GTK+ C code is so complicated and error prone that almost no C coders do it. As a C++ developer you know that derivation is an essential Object Orientated technique.
  • Member instances can be used, simplifying memory management. All GTK+ C widgets are dealt with by use of pointers. As a C++ coder you know that pointers should be avoided where possible.
  • Less code. The GTK+ C object model uses prefixed function names and cast macros. For instance: gtk_button_set_text(GTK_BUTTON(button), "sometext"); gtkmm C++ code is shorter and clearer. For instance: button.set_text("sometext");
  • There's no need to worry about GTK+'s inconsistent reference-counting policy.

Source: http://live.gnome.org/gtkmm/FAQ

Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
Matt
  • 5,478
  • 9
  • 56
  • 95
  • Thanks! I think I have found my answer! – phongvcao Apr 11 '11 at 03:16
  • What do you mean by "There's no need to worry about GTK+'s inconsistent reference-counting policy." ? – liberforce Apr 12 '11 at 08:40
  • @liberforce sorry I'm not familiar enough with the library to know that, I just got that info from the link mentioned. I'd imagine it means they do their own reference counting which works better than GTK+'s default behavior (less memory leaks?). But I'm not the best one to ask, I just gave the asker the answer he was looking for. – Matt Apr 13 '11 at 04:57
  • oh, I didn't notice it was a copy/paste of the GNOME wiki. In fact the person who edited it is Murray Cumming, lead GTKmm developper, so I suppose he knows his stuff, but it is the first time I see complaints about that. – liberforce Apr 13 '11 at 09:00