GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 23, 2014 2:20 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Wed Oct 10, 2012 11:39 am 
Offline

Joined: Wed Oct 10, 2012 11:19 am
Posts: 3
I am studng how to use gtk_file_selection_new funcation. But when I build the following code with cmd
Quote:
gcc file_selection.c -o file_selection `pkg-config --cflags --libs gtk+-2.0 `.
, gcc displays the error: invalid type argument of ‘->’ (have ‘int’).I test the code with both libgtk2.20.1 and libgtk3.4.2.Same error.
Code:
#include        <gtk/gtk.h>

GtkWidget *FileSelection;
void OpenFile(GtkWidget *widget,gpointer *data);
void button_event(GtkWidget *widget, gpointer *data);

int main(int argc,char *argv[ ])
{
        GtkWidget *window;
        GtkWidget *button;

        gtk_init(&argc,&argv);
        window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_widget_set_size_request(window,100,100);
        gtk_signal_connect(GTK_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);

        button=gtk_button_new_with_label("open file");
        gtk_signal_connect(GTK_OBJECT(button),"clicked",G_CALLBACK(button_event),NULL);
        gtk_container_add(GTK_CONTAINER(window),button);

        gtk_widget_show(button);
        gtk_widget_show(window);
        gtk_main();
}

void button_event(GtkWidget *widget,gpointer *data)
{
        FileSelection= gtk_file_selection_new("file selecton");
        g_signal_connect(GTK_OBJECT(GTK_FILL_SELECTION(FileSelection)->ok_button),"clicked",GTK_SIGNAL_FUNC(OpenFile),NULL);
        gtk_widget_show(FileSelection);
}

void OpenFile(GtkWidget *widget,gpointer *data)
{
        g_printf("%s\n",gtk_file_selection_get_filename(GTK_FILE_SELECTION(FileSelection)) );
}



Top
 Profile  
 
 Post subject: Re: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Wed Oct 10, 2012 5:48 pm 
Offline
Familiar Face

Joined: Wed Oct 10, 2012 5:42 pm
Posts: 5
Hi all.
I am newbie here :)

It looks like you have to write:

Code:
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->ok_button),"clicked",GTK_SIGNAL_FUNC(OpenFile),NULL);


instead of your:

Code:
g_signal_connect(GTK_OBJECT(GTK_FILL_SELECTION(FileSelection)->ok_button),"clicked",GTK_SIGNAL_FUNC(OpenFile),NULL);


i.e. you wrote GTK_FILL_SELECTION and should GTK_FILE_SELECTION


Top
 Profile  
 
 Post subject: Re: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Wed Oct 10, 2012 5:58 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello and welcome to the GTK+ forums (both of you;)!

Actually, none of the code is correct. Widgets are opaque structures whose contents should not be manipulated directly (you can only use public API). Use gtk_dialog_run() or something to get notified when user made selection. BTW, what would your code do if user pressed cancel or closed dialog using X in window title bar?

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Thu Oct 11, 2012 3:33 am 
Offline

Joined: Wed Oct 10, 2012 11:19 am
Posts: 3
Lounger wrote:
Hi all.
I am newbie here :)

It looks like you have to write:

Code:
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->ok_button),"clicked",GTK_SIGNAL_FUNC(OpenFile),NULL);


instead of your:

Code:
g_signal_connect(GTK_OBJECT(GTK_FILL_SELECTION(FileSelection)->ok_button),"clicked",GTK_SIGNAL_FUNC(OpenFile),NULL);


i.e. you wrote GTK_FILL_SELECTION and should GTK_FILE_SELECTION

Thank you! I am too careless!


Top
 Profile  
 
 Post subject: Re: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Thu Oct 11, 2012 3:37 am 
Offline

Joined: Wed Oct 10, 2012 11:19 am
Posts: 3
Quote:
BTW, what would your code do if user pressed cancel or closed dialog using X in window title bar?

these code is just a part of whole project


Top
 Profile  
 
 Post subject: Re: error: invalid type argument of ‘->’ (have ‘int’)
PostPosted: Thu Oct 11, 2012 11:06 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

huangya90 wrote:
these code is just a part of whole project


This doesn't change a thing. Your code is using undocumented private API and it'll break eventually. Try compiling your app in GTK+-3.0 and what I mean.

Cheers,
Tadej


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 guests


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