[glade--]Problems with glade_get_widget_tree() during runtime

Mukund Gopalan <[email protected]> Wed, 17 Mar 2004 01:18:15 -0800 (PST)
Newsgroups gmane.comp.gnome.glademm
Message-ID <[email protected]>
Hi all,

Let me start by thanking this group for helping me
(through online posts, though indirectly) with the
problems I've had so far with Glade.  Thank you all
much :)

Following is what I am facing now:

I have made a simple GUI with Glade.  The code being
produced is in C++.  The GUI contains a button and a
textview.  Upon pressing the button, I am trying to
display the text "Button pressed" in the textview. 
The signal handler code looks as follows:

---------------------
void window::on_button_clicked()
{                                                     
                      
   gchar output[50] = "Button clicked\n";
   GladeXML *xml;
   GtkTextView *textview;
                                                      
                         
   xml = glade_get_widget_tree(GTK_WIDGET(button));
   textview =  (GtkTextView*)glade_xml_get_widget(xml,
"textview");
                                                      
                         
   GtkTextBuffer* buf = 
gtk_text_view_get_buffer(textview);
   gtk_text_buffer_insert_at_cursor(buf, output,
strlen(output));
}
-----------------------

The code compiles fine, but when I run it it gives me
the following errors  in the console , upon pressing
the button:

-----------------------
(AA:19940): GLib-GObject-WARNING **: invalid cast from
`(null)' to `GtkWidget'
                                                      
                         
(AA:19940): Gtk-WARNING **: invalid cast from
`(unknown)' to `(unknown)'
                                                      
                         
(AA:19940): Gtk-CRITICAL **: file gtkobject.c: line
661 (gtk_object_get_data_by_id): assertion
`GTK_IS_OBJECT (object)' failed
                                                      
                         
** (AA:19940): CRITICAL **: file glade-xml.c: line 544
(glade_xml_get_widget): assertion `self != NULL'
failed.
                                                      
                         
(AA:19940): Gtk-CRITICAL **: file gtktextview.c: line
1210 (gtk_text_view_get_buffer): assertion
`GTK_IS_TEXT_VIEW (text_view)' failed
                                                      
                         
(AA:19940): Gtk-CRITICAL **: file gtktextbuffer.c:
line 598 (gtk_text_buffer_insert_at_cursor): assertion
`GTK_IS_TEXT_BUFFER (buffer)' failed
---------------------

I then commented out all but the first line:

----------------------
void window::on_button_clicked()
{                                                     
                      
   gchar output[50] = "Button clicked\n";
   GladeXML *xml;
   GtkTextView *textview;
                                                      
                         
   xml = glade_get_widget_tree(GTK_WIDGET(button));
//   textview = 
(GtkTextView*)glade_xml_get_widget(xml, "textview");
                                                      
                         
//   GtkTextBuffer* buf = 
gtk_text_view_get_buffer(textview);
//   gtk_text_buffer_insert_at_cursor(buf, output,
strlen(output));
}
-------------------

I compiled and ran the code, and got the errors:

--------------------- 
(AA:20793): GLib-GObject-WARNING **: invalid cast from
`(null)' to `GtkWidget'
 
(AA:20793): Gtk-WARNING **: invalid cast from
`(unknown)' to `(unknown)'
 
(AA:20793): Gtk-CRITICAL **: file gtkobject.c: line
661 (gtk_object_get_data_by_id): assertion
`GTK_IS_OBJECT (object)' failed
-----------------------

So as one can see the problem is the conversion of
'button' to a widget.  

I have made the window, the button, and the textview
public.  

Has anyone experienced such a problem before?

Any help would be appreciated.

Again, the code is in C++.

Thanks in advance,
Mukund Gopalan


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com