GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 22, 2014 1:58 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Problems with gtk_text_view_get_buffer ()
PostPosted: Sun Jan 08, 2012 4:50 pm 
Offline

Joined: Fri Aug 28, 2009 12:57 am
Posts: 2
Hi,

I'm writing a small app to display the contents of text files and I have the following code:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <gtk/gtk.h>

void
on_window_destroy (GtkObject *object, gpointer user_data)
{
        gtk_main_quit();
}

int
main (int argc, char *argv[])
{
        GtkBuilder              *builder;
        GtkWidget               *window;
   GtkWidget      *textview;
   GtkTextBuffer      *textbuffer;

        gtk_init (&argc, &argv);
       
        builder = gtk_builder_new ();
        gtk_builder_add_from_file (builder, "fv.xml", NULL);

        window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
        gtk_builder_connect_signals (builder, NULL);         
        g_object_unref (G_OBJECT (builder));

   textview = gtk_text_view_new ();

line 32: textbuffer = gtk_text_view_get_buffer (textview);

   gtk_widget_show (window);       
        gtk_main ();
       
        return 0;
}


and the following is the output from the compiler, gcc version 4.3.2 (Debian 4.3.2-1.1):

Code:
greg@debian:/fv$ gtk-builder-convert fv.glade fv.xml
Wrote fv.xml
greg@debian:/fv$ gcc -Wall -g -o fv fv.c -export-dynamic `pkg-config --cflags --libs gtk+-2.0`
fv.c: In function ‘main’:
fv.c:32: warning: passing argument 1 of ‘gtk_text_view_get_buffer’ from incompatible pointer type


I've tried passing textview, *textview and &textview, but I still get this warning and it seems to be tied into problems I'm having expanding my code. Is there any way to get rid of this warning? Am I using the correct syntax in the code I have posted?

Thanks.


Top
 Profile  
 
 Post subject: Re: Problems with gtk_text_view_get_buffer ()
PostPosted: Mon Jan 09, 2012 7:40 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Hi,

The C pointer you are trying to pass is of the incorrect type and you will need to cast it to the right type to get rid of the warning.

Change the line
Code:
  textbuffer = gtk_text_view_get_buffer (textview);
to
Code:
  textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(textview));


The macro GTK_TEXT_VIEW() will do the casting for you and check that it really points to a GtkTextView and not some other type of widget.

Note most calls to create a widget will return GtkWidget as this is the base of all widgets and you will in most cases need to do some casting using the GTK macros to get to your actual widget.

Edited for my silly mistakes!

_________________
E.


Last edited by errol on Mon Jan 09, 2012 8:23 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Problems with gtk_text_view_get_buffer ()
PostPosted: Mon Jan 09, 2012 4:29 pm 
Offline
GTK+ Geek

Joined: Sun Apr 03, 2011 11:12 am
Posts: 63
Hey, I think it should be GTK_TEXT_VIEW() not GTK_TEXTVIEW (as far as, I know. In gtk+2 I have used GTK_TEXT_VIEW only haven't tried GTK_TEXTVIEW()).


Top
 Profile  
 
 Post subject: Re: Problems with gtk_text_view_get_buffer ()
PostPosted: Mon Jan 09, 2012 8:22 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 745
Location: UK
Yes the macro should be GTK_TEXT_VIEW() my mistake. It was one of the last things I did before rushing off to work.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Problems with gtk_text_view_get_buffer ()
PostPosted: Tue Jan 10, 2012 2:13 am 
Offline

Joined: Fri Aug 28, 2009 12:57 am
Posts: 2
Thanks! So far so good.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group