gpt4 book ai didi

gcc - 如何用gtk3编译gtk2.0程序?

转载 作者:行者123 更新时间:2023-12-02 20:20:32 27 4
gpt4 key购买 nike

我有一个简单的程序,在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;
}

最佳答案

您需要将 gtk_timeout_add 调用更改为 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”将为您提供示例,例如这个,http://gna.org/patch/?2563 .

关于gcc - 如何用gtk3编译gtk2.0程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7358225/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com