[Glade-users] Help with textview
- From: z3026109 at student.unsw.edu.au (Nor Azhar Sa'ad)
- Subject: [Glade-users] Help with textview
- Date: Wed Oct 5 08:28:05 2005
HI. Thanks for the reply. I never used gdb before, and juz tried it. I don't
know how to really do that, as I am editing the file callbacks.c but in glade it
is all connected and is compiled by make. Can anyone give me a hand. Also, for
reference, I attached the function that I am having trouble with.
P/s : the itoa function work opposite way to atoi.
void
on_button12_clicked (GtkButton *button,
gpointer user_data)
{
gint fline,row,col, i, j, k,cloc, collength,len,matrixD, noOfStates,rowNoA,
rowNoB, user_input, linecount, charcount;
gchar A[MAXSIZE], B[MAXSIZE], matrixA[MAXSIZE][MAXSIZE],
matrixB[MAXSIZE],
matrixC[MAXSIZE],stringEntered[MAXENTRY][100],element[100];
gchar *text1,*text2,*text3,*text4,*text5,*text6,*text7, *matA;
gchar c, l, rowC;//, *text;
GtkTextBuffer *buffer1;
GtkWidget *textview1;
/*GtkWidget
*entry1,*entry2,*entry3,*entry4,*entry5,*entry6,*entry7,*entry8,*entry9,
*entry10,*entry11,*entry12,*entry13,*entry14,*entry15,*entry16,*entry17,
*entry18,*entry19,*entry20,*entry21,*/
GtkWidget *entry[MAXENTRY];//, stringEntered[MAXENTRY];
GtkWidget *spinbutton1,*spinbutton3,*spinbutton4;
*textview1;
GtkTextTagTable *textTagTable;
GtkTextIter *iter, *start_iter, *end_iter;
entry[1] = lookup_widget(GTK_WIDGET(button), "entry1");
entry[2] = lookup_widget(GTK_WIDGET(button), "entry2");
entry[3] = lookup_widget(GTK_WIDGET(button), "entry3");
entry[4] = lookup_widget(GTK_WIDGET(button), "entry4");
entry[5] = lookup_widget(GTK_WIDGET(button), "entry5");
entry[6] = lookup_widget(GTK_WIDGET(button), "entry6");
entry[7] = lookup_widget(GTK_WIDGET(button), "entry7");
entry[8] = lookup_widget(GTK_WIDGET(button), "entry8");
entry[9] = lookup_widget(GTK_WIDGET(button), "entry9");
entry[10] = lookup_widget(GTK_WIDGET(button), "entry10");
entry[11] = lookup_widget(GTK_WIDGET(button), "entry11");
entry[12] = lookup_widget(GTK_WIDGET(button), "entry12");
entry[13] = lookup_widget(GTK_WIDGET(button), "entry13");
entry[14] = lookup_widget(GTK_WIDGET(button), "entry14");
entry[15] = lookup_widget(GTK_WIDGET(button), "entry15");
entry[16] = lookup_widget(GTK_WIDGET(button), "entry16");
entry[17] = lookup_widget(GTK_WIDGET(button), "entry17");
entry[18] = lookup_widget(GTK_WIDGET(button), "entry18");
entry[19] = lookup_widget(GTK_WIDGET(button), "entry19");
entry[20] = lookup_widget(GTK_WIDGET(button), "entry20");
entry[21] = lookup_widget(GTK_WIDGET(button), "entry21");
spinbutton1 = lookup_widget(GTK_WIDGET(button), "spinbutton1");
spinbutton3 = lookup_widget(GTK_WIDGET(button), "spinbutton3");
spinbutton4 = lookup_widget(GTK_WIDGET(button), "spinbutton4");
textview1 = lookup_widget(GTK_WIDGET(button), "textview1");
linear.num_states = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
(spinbutton1));
linear.user_input = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
(spinbutton3));
linear.matrixD = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON (spinbutton4));
//get all the string input into each text entry
len = strlen(gtk_entry_get_text(GTK_ENTRY(entry[i])));
//cloc = len - (len-i);
for(i=1; i<=MAXENTRY; i++)
{
stringEntered[i][len] = gtk_entry_get_text(GTK_ENTRY(entry[i]));
}
//for matrixA
for(k=12,i=1 ; k<=21,i<linear.num_states ; k++,i++)
{
//for(i=1; i<=linear.num_states; i++)
{
for(j=0; j<=len; j++)
{
c=(stringEntered[k][j]);
if((c!= '\n') && (c !=','))
{
linear.matrixA[i][j] = c;
// printf("%c", c);
}
// printf("\n");
}
}
}
matA = linear.matrixA[i][j];
//for matrixB
for(k=2,i=1; k<= 11,i<=linear.num_states; k++, i++)
{
//for(i=1; i<=linear.num_states; i++)
//{
linear.matrixB[i] = (stringEntered[i][len]);
//printf("%c\n", linear.matrixB);
//}
}
//for matrixC
//element[j]= (stringEntered[1][len]);
for(k=(len-(len-1)); k<=len; k++)
{
if(stringEntered[1][k] != ',')
{
i=1;
linear.matrixC[i] = stringEntered[1][k];
i++;
}
}
//i = 1;
/*for(j=0; j<len; j++)
{
if(element[j]!=',')
{
linear.matrixC[i] = element[j];
//g_print("c",linear.matrixC[i]);
i++;
}
}*/
//If you don't call gtk_text_view_set_buffer() before using the text view, an
empty default buffer will be created for you. Get the buffer with
gtk_text_view_get_buffer().
text1 = "System : Linear System";
text2 = "Number of States : ";
text3 = "Matrix A = ";
text4 = "Matrix B = ";
text5 = "Matrix C = ";
text6 = "Matrix D = ";
text7 = "User Input = ";
buffer1 = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview1));
linecount = gtk_text_buffer_get_line_count(buffer1);
charcount = gtk_text_buffer_get_char_count(buffer1);
gtk_text_buffer_get_start_iter(buffer1,iter);
//get the first line of the buffer
fline = linecount-(linecount-1);
gtk_text_buffer_set_text (buffer1, "Hello, this is some text", -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+1));
gtk_text_buffer_insert(buffer1, iter, text1, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+2));
gtk_text_buffer_insert(buffer1, iter, text2, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+3));
gtk_text_buffer_insert(buffer1, iter, itoa(linear.num_states), -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+4));
gtk_text_buffer_insert(buffer1, iter, text3, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+5));
gtk_text_buffer_insert(buffer1, iter, matA, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+6));
gtk_text_buffer_insert(buffer1, iter, text4, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+7));
gtk_text_buffer_insert(buffer1, iter, linear.matrixB, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(fline+8));
gtk_text_buffer_insert(buffer1, iter, text5, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(charcount+9));
gtk_text_buffer_insert(buffer1, iter, linear.matrixC, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(charcount+10));
gtk_text_buffer_insert(buffer1, iter, text6, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(charcount+11));
gtk_text_buffer_insert(buffer1, iter, itoa(linear.matrixD), -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(charcount+12));
gtk_text_buffer_insert(buffer1, iter, text7, -1);
gtk_text_buffer_get_iter_at_line(buffer1,iter,(charcount+13));
gtk_text_buffer_insert(buffer1, iter, itoa(linear.user_input), -1);
}
I would really like to know what makes my textview not diplaying the buffer.
Thanks in advance.
Quoting Damon Chaplin <damon karuna uklinux net>:
On Tue, 2005-10-04 at 00:21 +1000, Nor Azhar Sa'ad wrote:
Hi everyone.
I am using glade with C language for my undergraduate thesis project.
Currently
im having trouble with textview, where Ive put the input supplied by the
user
into a buffer and try to display it in the text view. However, the GUI
window
was automatically closed and I got the msg "Segmentation Fault" whenever
the
button that supposed to generate the response was clicked. Can anyone give
me a
hand on this? Also, I only found 3 tutorials on using glade from the
internet.
Is there anyway i can find more of those, particularly those with sample
using
textview?
Have you tried running it in gdb? You can then see where it crashed.
Run 'gdb <application-name>',
type 'r' to run the application,
click the button to crash the application
type 'bt' to get a stack trace.
You could post the relevant code here, and someone will probably spot
the mistake.
Damon
Regards,
Nor Azhar Sa'ad
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]