开发者

how to compile gtk2.0 program with gtk3?

i have a simple program which is compiled with gtk2.0 in ubuntu.In ubuntu11.04 i installed gtk3.then i compile the same code,i got an error in the following line

/* Add a timer callback to update the value of the progress bar */
timer = gtk_timeout_add (100, progress_timeout, pdata);

i just comment the line and recompile it.then i got output file.but it is not properly working without the commented line.

in gtk2.0 i compiled by the following command

gcc progressbar.c `pkg-config --cflags --libs gtk+-2.0`

and in gtk3

gcc progressbar.c `pkg-config --cflags --libs gtk+-3.0`

I have a doubt that,is there any deprecation in that method in gtk3.please give me a link to an easy documentation with examples.what are the main difference between 2 and 3. The full source code is as shown below

#include <gtk/gtk.h>

typedef struct _ProgressData {
GtkWidget *pbar; 
} ProgressData;

gint progress_timeout( gpointer data )
{
  ProgressData *pdata = (ProgressData *)data;
  gdouble new_val;
  new_val = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (pdata->pbar)) + 0.01;

  if (new_val > 1.0)
new_val = 0.0;

  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata->pbar), new_val);

  return TRUE;
} 


int main( int   argc,
      char *argv[])
{
ProgressData *pdata;
GtkWidget *align;
GtkWidget *window;

int timer;  

GtkWidget *vbox;

gtk_init (&argc, &argv);

/* Allocate memory for the data that is passed to the callbacks */
pdata = g_malloc (sizeof (ProgressData));

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);

    g_signal_connect ( window, "destroy", gtk_main_quit, NULL ) ;

gtk_window_set_title (GTK_WINDOW (window), "GtkProgressBar");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);

vbox = gtk_vbox_new (FALSE, 5);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);

/* Create a centering alignment object */开发者_开发百科
align = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);
gtk_widget_show (align);

/* Create the GtkProgressBar */
pdata->pbar = gtk_progress_bar_new ();

gtk_container_add (GTK_CONTAINER (align), pdata->pbar);
gtk_widget_show (pdata->pbar);

/* Add a timer callback to update the value of the progress bar */
timer = gtk_timeout_add (100, progress_timeout, pdata);


gtk_widget_show (window);

gtk_main ();

return 0;
}


You need to change the gtk_timeout_add call to g_timeout_add.

gtk_timeout_add ()

guint               gtk_timeout_add                     (guint32 interval,
                                                         GtkFunction function,
                                                         gpointer data);

Warning

gtk_timeout_add has been deprecated since version 2.4 and should not be used in 
newly-written code. Use g_timeout_add() instead.

Google "gtk_timeout_add g_timeout_add" will get you examples, e.g. this one, http://gna.org/patch/?2563.


As jesse told you, you're using gtk_timeout_add, which has been deprecated in GTK2. All the symbols deprecated in GTK2 were removed in GTK3.

To have your program work in GTK3, you need to make sure you don't use any GTK2-deprecated symbols. For this, use symbols like G_DISABLE_DEPRECATED (for GLib), GTK_DISABLE_DEPRECATED, etc. that can help you make sure when you compile with GTK2 that you're not using a symbol that was removed in GTK3.

There is also a GTK2 to GTK3 migration guide that you can use, as well as some GNOME Goals that link to the patches that were used in GNOME to accomplish that same task, for GLib and GTK symbols.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜