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



Wrinkled Shirt wrote:

Hi guys,

I looked through the archives for a solution to this problem, but the only solution I found still seg-faulted for me. Basically, if you want to create a GtkCList with titles, you need to use the function call

GtkWidget * grid;
char *blankrow[] = {"", "", "", ""};

gtk_clist_new_with_titles(4, blankrow);

The problem is, since I want to build the GtkCList with the result of an SQL query, I'm not going to know ahead of time exactly how many columns are going to be needed. I will be able to find out how many columns are needed after the program has started, and use that to dynamically create the blankrow, but so far, every way I've tried has come up empty. Hard-coding the blankrow like I did above isn't an option.

My question is this: how do I create blankrow of N columns containing N ""'s, during runtime? Maybe this is more of a C question than a Gtk question... if anybody could help, I'd really appreciate it. I'm going nuts here.

The only solution put forward, to initialize it using

widget = gtk_clist_new_with_titles(cols, "");

didn't work when I had more than 2 columns.

gtk_clist_new_with_titles() requires an array of pointers-to-strings that contains the same number of elements as there are columns. My straight C is rusty, but something along the lines of:

gint i = 0;
gint columncount = /* Returned from your SQL query */

gchar** titles = malloc(columncount * sizeof(gchar*));
for(i = 0; i < columncount; i++)
	titles[i] = "";
widget = gtk_clist_new_with_titles(columncount, titles);

... should do the trick. I don't recall whether GtkCList copies or references the strings in the array, so you'll have to experiment to see if you can do "free(titles);" immediately afterwards.

HTH,
Timothy M. Shead
tshead k-3d com





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