Is it possible to use GTK+ with C++?

11,706
  • 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

Share:
11,706
phongvcao
Author by

phongvcao

Updated on June 04, 2022

Comments

  • phongvcao
    phongvcao almost 2 years

    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?

    • MaddTheSane
      MaddTheSane about 13 years
      There are some great reasons on its homepage.
    • phongvcao
      phongvcao about 13 years
      Thanks for the quick reply! But is GTK+ able to do those?
    • RedX
      RedX about 13 years
      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.
    • phongvcao
      phongvcao about 13 years
      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
      phongvcao about 13 years
      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"
    • Philippe F
      Philippe F over 4 years
      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.
  • phongvcao
    phongvcao about 13 years
    Thanks! I think I have found my answer!
  • liberforce
    liberforce about 13 years
    What do you mean by "There's no need to worry about GTK+'s inconsistent reference-counting policy." ?
  • Matt
    Matt about 13 years
    @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.
  • liberforce
    liberforce about 13 years
    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.