Re: Problem with GtkCList, dynamically creating with N columns...



Hey again,

The original problem again was dynamically creating an array of blank strings to be used as an argument in creating a gtkclist widget. The point was to create some code that could replace:

/**/
char *blankrow[] = {"", "", ""};  // needed for three columns
/**/

...with something else that would build dynamically, assuming I already knew the value of the number of columns needed.

Based on Flavio's response (thanks Flavio), I did the following...

/**/

int *blankrow;
int ctr;

blankrow = (int *)malloc(vpsql->cols);  // vpsql->cols = # of cols
for (ctr=0; ctr<vpsql->cols; ctr++)
{
 (char *)blankrow[ctr] = (char *)malloc(2);
 sprintf((char *)blankrow[ctr]," ");
}

vpsql->grid = gtk_clist_new_with_titles(vpsql->cols, (char **)blankrow);

/**/

There's a lot of extra casting that I threw in there because of compile warnings, but the effect is pretty much the same with or without them. The thing works (thank god), although there are a couple of things that trouble me.

1. If I substitute the declarations, mallocs and for loop with the hard-coded alternative above, I get no runtime error messages. However, with the new declarations, mallocs and for loop, I get the following error message repeated quite a lot. I cannot quite figure out why...

"Gtk-CRITICAL **: file gtkbindings.c: line 1072 (gtk_pattern_match): assertion `pspec->match_type < GTK_MATCH_LAST' failed."

There doesn't seem to be any corelation between the number of times this error message appears, and the number of modifications I've made to the widget (most notably, gtk_clist_set_text and gtk_clist_set_column_title). There's only one other occurence of this error message on the internet that I could find, and it had to do with some guy trying to use the following code:

/**/
label = gtk_label_new("Start search in:");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5);
gtk_widget_show(label);
/**/

That was all he gave, so I don't really know if the error is somewhere else. Anyhow, the program is currently working fine, displaying query results etc., so I'm tempted to let this drop until a later date. But if anyone knows off the top of their head what this is...?

2. My C skills are really rudimentary, so I have no idea how to free up the memory I've malloced up there. I've tried a few things, but each time I do it I get an error. Considering that I'm asking for a very limited amount of memory, it's tempting to just let it go, but I suppose that wouldn't be proper.

Thanks once again for all the responses. It was really helpful, and the widget is coming along nicely, if noisily.
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.





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