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)) );
}