Re: how to access a widget ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I cracked the problem, was an matter of allocating space. Also not assigning &buttonreeks but buttonreeks.
Also one pointer and changing the value for every button was not good, in hindside very obvious because every button needs a different pointer otherwise every button will do the same (pointing to the same data). So I made an array of pointers.


That leaves me only with two questions:
1) Can this be achieved more simple ?
2) I declared "struct _buttonreeks *buttonreeks[30]; " because this is in most cases large enough, but how can I make it lenght-independant (what if I need 32 ??).
struct _buttonreeks *buttonreeks[] does not compile !!


for those who are interested the solution given below:

struct _buttonreeks *buttonreeks[30];
GtkWidget *button;
struct table_description foo;
GArray *buts = NULL;

buts = g_array_sized_new (FALSE, FALSE, sizeof (struct table_description), 1);

...etc...

for (i=0; i < vertical - 1; i++)
{
   .... other things .

  for (j=1; j < vertical; j++)
  {
   if ((i < j) && Link_exists(i,j))
   {
     button = gtk_button_new ();
     gtk_button_set_label ((GtkButton *) button , " x");
     gtk_table_attach_defaults (GTK_TABLE (table), button , 1 + j, 2 + j, 1 + i, 2 + i);
	
    foo.buttons = button;  // get the information and store it in the GArray
    foo.i = i;
    foo.j = j;
    g_array_append_vals (buts, &foo, 1);
    }
   }
}

// g_signal_connect for all buttons
for (i=0; i < buts->len; i++)
{
  buttonreeks[i] = (struct _buttonreeks *) g_malloc(sizeof(struct _buttonreeks));
  buttonreeks[i]->buttonids = buts;
  buttonreeks[i]->i = g_array_index (buts, struct table_description, i).i;
  buttonreeks[i]->j = g_array_index (buts, struct table_description, i).j;
  button = g_array_index (buts, struct table_description, i).buttons;
  g_signal_connect (G_OBJECT(button), "clicked",
                      (GCallback) toggle_location_event, buttonreeks[i]);
}


edward hage wrote:


Tiago Cogumbreiro wrote:


You can cache a matrix with your buttons and the last changed buttons in a structure[1] and then send this structure[2] as user data (in the callback).

...........

Thank you for the advice,
Got that, I made the following structures. Looks much like you proposed, only use GArray to fill it with buttons and location (i,j) info.


struct _buttonreeks
{
  GArray *buttonids;
  guint i;
  guint j;
};

struct table_description
{
  GtkButton *buttons;
  guint i;
  guint j;
};

I get the following error-message when I run the program (compiling and
linking all okay!)

edward@linux:~/Projects/modeller> ./modeller9

(modeller9:8722): GLib-GObject-WARNING **: invalid (NULL) pointer instance

(modeller9:8722): GLib-GObject-CRITICAL **: file gsignal.c: line 1861 (g_signal_connect_data): assertion `G_TYPE_CHECK_INSTANCE (instance)' failed
Segmentatie fout
edward@linux:~/Projects/modeller>


How can I solve this problem ?



_______________________________________________ gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux