LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GTK+ programmer: C or C++? (https://www.linuxquestions.org/questions/programming-9/gtk-programmer-c-or-c-311651/)

vharishankar 04-10-2005 07:57 AM

GTK+ programmer: C or C++?
 
After trying to get QT/Kdevelop to work, I finally gave up on it at present due to several problems when compiling programs (missing development libraries and so on). I know I can install the QT development libraries, but I thought I might try something different.

So I have installed Anjuta and I created a small GTK+ application and I find the C interface quite nice though a touch inconvenient.

I also like Glade much better than QT Designer/Kommander Editor. It's code generator is fantastic! :)

Now the question is, is there a better way to write GTK+ programs? Not that I don't like GTK+. Far from it. It is a fantastic API and I wish I had tried GTK+ before QT.

I know that GTKmm is a C++ wrapper for GTK+, but the problem is that I am not sure if writing GTKmm program will create additional dependencies as I needed to install more libraries (glibmm, glademm and gtkmm and so on).

Anybody can confirm this? Is it possible to actually write GTK+ programs which statically bind the C++ libraries so that the dependencies are limited to the standard GTK+ C libraries?

reddazz 04-10-2005 11:01 AM

i am not much of a programmer, but if you were to write c++ programs using gtkmm, then I am sure it would be a dependency on most systems. gtkmm itself would probably need a few extra support packages to be installed alongside it as well.

vharishankar 04-10-2005 12:01 PM

I suspected as much :(

Never mind, I'll stick to C. It's still a nice experience though. :) Feels much "ligher" than QT, if you can relate to that.

johnMG 04-10-2005 07:58 PM

If you like C++ -- real modern, correct, idiomatic C++ -- you'll probably like gtkmm.

I tried using gtkmm a year or two ago. At the time, it was difficult for me to get all the dependencies installed correctly (this was on redhat 9). I'm guessing that it's trivial to install on an apt-based system.

melinda_sayang 04-11-2005 04:44 AM

Look at my project. I made it using gtkmm.
http://wallpapoz.sf.net

However, I have made a static binary so the user does not need to install libraries. If the user want to install from source, the user need to install libxml++, glibmm, gtkmm, libglademm.

So I say.... go with gtkmm!!!!!

To make a static binary, I use this wonderful software:
http://statifier.sourceforge.net/

Don't use code generator. It is deprecated anyway.

vharishankar 04-11-2005 06:34 AM

Quote:

Don't use code generator. It is deprecated anyway.
You mean the one in Glade GTK or Glade GTKmm?

melinda_sayang 04-11-2005 07:52 AM

both of them.....

See here:
http://glade.gnome.org/todo.html

With regard to the last item, note that code generation has been deprecated for a long time: the preferred solution is using libglade. If you want to use code generation at any cost, the way to go is using an external tool to process the .glade file and output code in your language of choice. The format of the .glade file is the same as Glade-2.

vharishankar 04-11-2005 09:59 AM

Using libglade is another dependency. Why on earth should I want another dependency? I'd prefer code generation in GTK code, thank you very much.

I cannot understand some of the reasoning behind these design decisions.

melinda_sayang 04-11-2005 10:42 AM

Quote:

Originally posted by Harishankar
Using libglade is another dependency. Why on earth should I want another dependency?
# UI changes can be seen more quickly, so UIs are able to improve.
# Designers without programming skills can create and edit UIs.
# We don't have great gui builder integrated with IDE for GTK+ like Netbeans for Java or Delphi

vharishankar 04-11-2005 10:47 AM

Well there's nothing really much to be gained by separating the UI from the codebase. Especially when Glade integrates so well with an IDE like Anjuta. And I always like to be as less dependent on external libraries as possible.

So I really see no benefits even though the developers might tout it as a great improvement.

So, how easy/difficult is using libglade? I mean can you still reference the GTK widgets from the code easily using "lookup_widget"?

:( I have to keep re-learning again and again.

melinda_sayang 04-12-2005 05:30 AM

Quote:

Originally posted by Harishankar

So, how easy/difficult is using libglade? I mean can you still reference the GTK widgets from the code easily using "lookup_widget"?

This is basic code using libglademm ( c++, part of gtkmm ), so you can judge your self.
Code:

#include <libglademm/xml.h>
#include <gtkmm.h>
#include <iostream>

Gtk::Dialog* pDialog = 0;

void on_button_clicked()
{
  if(pDialog)
    pDialog->hide(); //hide() will cause main::run() to end.
}

int main (int argc, char **argv)
{
  Gtk::Main kit(argc, argv);

  //Load the Glade file and instiate its widgets:
  Glib::RefPtr<Gnome::Glade::Xml> refXml;
  try
  {
    refXml = Gnome::Glade::Xml::create("basic.glade");
  }
  catch(const Gnome::Glade::XmlError& ex)
  {
    std::cerr << ex.what() << std::endl;
    return 1;
  }

  //Get the Glade-instantiated Dialog:
 
  refXml->get_widget("DialogBasic", pDialog);
  if(pDialog)
  {
    //Get the Glade-instantiated Button, and connect a signal handler:
    Gtk::Button* pButton = 0;
    refXml->get_widget("quit_button", pButton);
    if(pButton)
    {
      pButton->signal_clicked().connect( sigc::ptr_fun(on_button_clicked) );
    }

    kit.run(*pDialog);
  }

  return 0;
}


vharishankar 04-12-2005 08:20 AM

melinda_sayang. Thanks for the code.

But I must say, since you told me to use libglade, I tried to install the libglade-dev package and its dependencies are so deep that it requires (almost) a whole Gnome install (I tried in apt in debian)!

That defeats the very purpose of my program. I want a simple GTK program which has very few dependencies apart from the GTK libraries.

Give me a good reason to use libglade. I don't see any reason to use it, unless Debian is quite wrong in asking for so many dependencies.

melinda_sayang 04-12-2005 10:23 AM

What is the dependencies anyway??? As long as I know, libglade has nothing to do with gnome..... only with gtk+

This is my guess. Debian want to install the recommended package too with your library.....

I will give reason for using libglade in your project. To make your life easier. If you scare that would make the installation hard, consider autopackage.

http://www.autopackage.org

mhearn 04-13-2005 12:00 PM

Hi,

I wouldn't worry about using GTKmm or libglade. In particular:

- libglade and GTK+ are installed on nearly all Linux distributions.
- The GTKmm bindings are not, but they can be statically linked if you wish to build an autopackage style installer

I've used GTKmm a bit, and they are very nice bindings indeed. I'd strongly recommend them.

MA_D 04-13-2005 08:10 PM

I recommend against gtkmm. Gtk2 is already a very object oriented structure, and it's wonderful to code in. You can just use it in your c++ program; obviously the wierdest things are like converting between string and gchar.. But I would definitely recommend not using gtkmm.

There I think are things to make your app easily portable to things like windows, but I don't know if that's something you want.

Remember, c++ can always compile against c libraries.


All times are GMT -5. The time now is 09:24 PM.