我有一个在 ubuntu 中用 gtk2.0 编译的简单程序。在 ubuntu11.04 中我安装了 gtk3。然后我编译了相同的代码,我在下面的行中出现错误
/* Add a timer callback to update the value of the progress bar */
timer = gtk_timeout_add (100, progress_timeout, pdata);
我只是注释该行并重新编译它。然后我得到了输出文件。但是如果没有注释行,它就无法正常工作。
在gtk2.0中我通过以下命令编译
gcc progressbar.c `pkg-config --cflags --libs gtk+-2.0`
在 gtk3 中
gcc progressbar.c `pkg-config --cflags --libs gtk+-3.0`
我怀疑,在 gtk3 中该方法是否有任何弃用。请给我一个带有示例的简单文档的链接。2 和 3 之间的主要区别是什么。完整的源代码如下所示
#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;
}