Re: Problem with GtkCList a dynamically creating with N columns...
- From: Flavio Ribeiro <flavio hackpalace com>
- To: Wrinkled Shirt <wrinkledshirt hotmail com>, gtk-list <gtk-list gnome org>
- Subject: Re: Problem with GtkCList a dynamically creating with N columns...
- Date: Mon, 29 Jan 2001 17:50:27 -0200
This is really a C question.
What you need to do is find the number of columns and create the array
during runtime. With a C99 compatible compiler you can actually declare
an array anywhere inside a function so this wouldn't be a problem. With
most common compilers like gcc you'll have to manually create this array.
I've written a quick and dirty example on how to do this. Here it is:
int main(void){
int *ptr;
ptr = (int *) malloc(16);
ptr[0] = malloc(256);
ptr[1] = malloc(256);
ptr[2] = malloc(256);
ptr[3] = malloc(256);
sprintf(ptr[0],"test string");
printf("%s\n",ptr[0]);
}
The lines with the mallocs create your array of strings. A pointer in
i386 takes 4 bytes so I allocate 4 pointers with malloc(16). I set each
one of them to an area with 256 bytes.
Then I copy a string to the first area and print it.
Note that this example is dirty AND dangerous. Print a string longer
than 255 bytes to ptr[x] is the perfect buffer overflow as there's no
bounds checking here.
Use the analog functions contained in Glib to make this secure and more
portable. (oh, and don't forget to free() the array after you use it!!)
In case this isn't very clear to you, write me with any questions.
Best regards,
Flavio
--
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.
(alternate question, is this one of the things that's going to be dealt
with in the upgrade to Gtk2? I read both GtkCList and GtkCTree are
supposed to be dropped or something for that release...)
Sorry for any typos.
-andrew
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]