Re: [gtk-list] Gtk and C++ ?



Cyril Picard wrote:

> Is it possible to use gtk in a C++ program ??

Yes.

> I've tried this sample :
>
> // BEGIN
>
> #include <gtk/gtk.h>
>
> void main(int argc, char *argv[])
> {
>   GtkWidget *Dialogue, *Label, *Bouton;
>
>
>   gtk_init(&argc, &argv);
>
>   // Fenetre principale
>   Dialogue = gtk_dialog_new();
>   gtk_window_set_title(GTK_WINDOW(Dialogue), "Hello, World");
>   gtk_widget_show(Dialogue);
>
>   // Le label "Hello World"
>   Label = gtk_label_new("Bonjour, World");
>   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->vbox), Label, TRUE,
> TRUE, 0);
>   gtk_widget_show(Label);
>
>   // Le bouton Fermer
>   Bouton = gtk_button_new_with_label("Fermer");
>
>   gtk_signal_connect_object(GTK_OBJECT(Bouton), "clicked",
> (GtkSignalFunc)gtk_exit,
> NULL);
>   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(Dialogue)->action_area),
> Bouton, TRUE,
> TRUE, 0);
>   gtk_widget_show(Bouton);
>
>   gtk_main();
>
>
>   gtk_main();
> }
>
> // END
>
> and when I use gcc to compile, it raises the following error :
>
> hellogtk.cpp: In function `int main(...)':
> hellogtk.cpp:21: ANSI C++ forbids implicit conversion from `void *' in
> argument passing

The problem is that glib defines NULL like this:

    #define NULL ((void*) 0)

but gtk_signal_connect_object expects a GtkObject* as the last
parameter. Either cast the NULL to a GtkObject* or just use 0 (zero)
instead.

There is also a c++ library that wraps the gtk 'c' library. It's called
Gtk-- and there's a link to the Gtk-- web site from the gtk web site
(www.gtk.org).

Cheers.

--
Matt Goodall             |  Isotek Electronics Ltd
email: mgg@isotek.co.uk  |  Claro House, Servia Road
Tel: +44 113 2343202     |  Leeds, LS7 1NL
Fax: +44 113 2342918     |  England





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]