gtk function with argv

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

gtk function with argv

Rúben Rodrigues
Why guys,

I have a doubt that is more about C language that gtk+ but it's to apply
to gtk+.

I have this function:

GtkChart vChart_Init(GtkWidget *widget, GtkSeries *series)

My doubt is: How can i use function like this:
vChart_Init(GTK_WIDGET(widget), "Series A", "Series B", "Series C");

I need that second parameter is dynamic  and is a string (that contains
the name of serie)

THanks

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: gtk function with argv

Gtk+ - Apps Dev mailing list

 
Hi Ruben,

I think what you are looking for is a C variadic function. Something that works like g_object_set() with a Null terminated list of arguments.

Using dynamic glib containers might be a better choice. It is simpler to just pass a single pointer with your user_data to functions which is how GTK callbacks are setup. Also, I have read that variadics have some troubles and don't always work well if you call the functions from another language.

Eric


//gcc -Wall ptr_array1.c -o ptr_array1 `pkg-config --cflags --libs glib-2.0`
 
#include<glib.h>
#include<stdarg.h>

static void vChart_Init1(gchar *widget, GPtrArray *series)
  {
    g_print("Init1\n");
    gint i=0;
    gint length=series->len;
    for(i=0;i<length;i++) g_print("%s\n", (gchar*)g_ptr_array_index(series, i));
  }
static void vChart_Init2(gchar *widget,...)
  {
    g_print("Init2\n");
    gchar *temp=widget;
    if(temp!=NULL)
      {
        va_list var_args;  
        va_start(var_args, widget);
        while(temp!=NULL)
          {
            g_print("%s\n", temp);
            temp=va_arg(var_args, gchar*);
          }
        va_end(var_args);
      }
  }
int main()
  {
    gchar *widget="widget";
    gchar *string1="Series A";
    gchar *string2="Series B";
    gchar *string3="Series C";
    GPtrArray *series=g_ptr_array_new();
    g_ptr_array_add(series, string1);
    g_ptr_array_add(series, string2);
    g_ptr_array_add(series, string3);

    vChart_Init1(widget, series);
    vChart_Init2(widget, string1, string2, string3, NULL);
    vChart_Init2(widget, "Series A", "Series B", "Series C", NULL);

    g_ptr_array_unref(series);

    return 0;
  }


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list