Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

c

gtk

gtkmm

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?

like image 924
phongvcao Avatar asked Apr 11 '11 03:04

phongvcao


People also ask

Can you use GTK with C?

Language BindingsGTK is written in C but has been designed to support a wide range of languages such as Python, JavaScript, C++, Rust and many more.

Is GTK C or C++?

GTK is entirely written in C and the GTK+ software that we commonly use in Linux are also written in C. The desktop managers, such as GENOME and XFCE, also are built using GTK.

Is C good for GUIs?

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.


1 Answers

  • 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

like image 80
Matt Avatar answered Sep 29 '22 08:09

Matt