GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 3:52 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: several checkboxes with different behaviour
PostPosted: Thu Jun 26, 2008 3:58 pm 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:16 pm
Posts: 14
Hello everybody!

I'd like to dynamically create several checkboxes ... have a look at my code:

Code:
   GtkWidget *checkBox;
   int i = 0;
   while(i < 100) {
      if (strcmp(options[i],"\0")) {
         checkBox = gtk_check_button_new_with_label(options[i]);
         gtk_box_pack_start (GTK_BOX (contentBox), checkBox, FALSE, FALSE, 1);
         g_signal_connect (G_OBJECT (checkBox), "toggled", G_CALLBACK (toggled), NULL);
      }
      i++;
   }


The problem now is that all the checkboxes do the same: they call the function "toggled" ... how can I give the variable i to the toggle-function so that I can make all buttons do something different?

Thank you for your help!

Zarg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 4:29 pm 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
well, if your toggled callback follows the prototype:
Code:
void                user_function                      (GtkToggleButton *togglebutton,
                                                        gpointer         user_data)

then you'll already have the unique button in the form of togglebutton.
if you want to pass i to toggled, then do:
Code:
g_signal_connect(G_OBJECT(checkBox), "toggled", G_CALLBACK(toggled), (gpointer)i);

then in toggled, (gint)user_data should be the same as i.

also, just out of curiosity, what type is options, char* or char**?
because if it's char*, then you're passing a char to gtk_check_button_new_with_label, but it wants a char*:
http://library.gnome.org/devel/gtk/stab ... with-label


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 26, 2008 7:24 pm 
Offline
Familiar Face

Joined: Sun Mar 09, 2008 2:16 pm
Posts: 14
Hello!

Thank you for your fast answer!
Everything works now, great!

I declared options like this:

Code:
char options[100][100];


I hope this is correct? It seems to work ...

Thanks!
Zarg


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 2:26 am 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
yeah, that's just fine.
I was confused because I read "\0" as '\0', so I thought it was a char*,
it seems that I need to give my eyes a break...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group