IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec C & C++ Discussion :

(gtk:8098): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkTextView'


Sujet :

GTK+ avec C & C++

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    79
    Détails du profil
    Informations personnelles :
    Âge : 30
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 79
    Points : 63
    Points
    63
    Par défaut (gtk:8098): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkTextView'
    Bonjour,
    J'ai essayer de faire un programme avec GTK+
    Mais lorsque je l'execute, et que je choisis un fichier avec le bouton "Open", sa m'envoi dans la console :

    (gtk:8098): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkTextView'
    J'ai compiler mon programme avec GCC :
    gcc `pkg-config --cflags --libs gtk+-2.0` gtk.c -o gtk
    gtk.c: In function «gsa_OpenFile":
    gtk.c:66: attention : initialization makes integer from pointer without a cast
    gtk.c:67: attention : assignment makes integer from pointer without a cast
    gtk.c:68: attention : passing argument 1 of «gsa_OpenedFile" makes pointer from integer without a cast
    gtk.c:69: attention : passing argument 1 of «g_free" makes pointer from integer without a cast
    gtk.c:69: attention : assignment makes integer from pointer without a cast
    La ligne 66 est "gchar fileName = NULL;"

    Le source (je savais pas quelle partie mettre alors j'ai tout mis :s)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    #include <stdlib.h>
    #include <gtk/gtk.h>
     
    void gsa_OpenFile(gpointer userDatas);
    static void gsa_OpenedFile(const gchar *fileName,GtkTextView *textArea);
     
    int main(int argc,char *argv[])
    {
    	GtkWidget *window = NULL;
    	GtkWidget *generalContainer = NULL;
    	GtkWidget *textView = NULL;
    	GtkWidget *openButton = NULL;
    	GtkWidget *quitButton = NULL;
     
    	/* window */
    	{
    		gtk_init(&argc,&argv);
    		window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    		gtk_window_set_title(GTK_WINDOW(window),"Gabbec");
    	}
     
    	/* container */
    	{
    		generalContainer = gtk_hbutton_box_new();
    		gtk_container_add(GTK_CONTAINER(window),generalContainer);
    	}
     
    	/* Text */
    	{
    		textView = gtk_text_view_new();
    		gtk_box_pack_start(GTK_BOX(generalContainer),textView,TRUE,TRUE,0);
    	}
     
    	/* quit */
    	{
    		quitButton = gtk_button_new_from_stock(GTK_STOCK_QUIT);
    		g_signal_connect(G_OBJECT(quitButton),"clicked",G_CALLBACK(gtk_main_quit),NULL);
    		gtk_box_pack_start(GTK_BOX(generalContainer),quitButton,FALSE,FALSE,0);
    	}
    	/* openButton */
    	{
    		openButton = gtk_button_new_from_stock(GTK_STOCK_OPEN);
    		g_signal_connect(G_OBJECT(openButton),"clicked",G_CALLBACK(gsa_OpenFile),NULL);
    		gtk_box_pack_start(GTK_BOX(generalContainer),openButton,FALSE,FALSE,0);
    	}
     
    	g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
     
    	gtk_widget_show_all(window);
    	gtk_main();
     
    	return EXIT_SUCCESS;
    }
     
    void gsa_OpenFile(gpointer userDatas)  
    {
    	GtkWidget *dialog = NULL;
    	dialog = gtk_file_chooser_dialog_new("Ouvrir un fichier",NULL,
    																				GTK_FILE_CHOOSER_ACTION_OPEN,
    	                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
    			                                  GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,NULL);
    	if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
    	{
    		gchar fileName = NULL;
    		fileName = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
    		gsa_OpenedFile(fileName,GTK_TEXT_VIEW(userDatas));
    		g_free(fileName),fileName = NULL;
    		gtk_widget_destroy(dialog);
    	}
    }
     
    static void gsa_OpenedFile(const gchar *fileName,GtkTextView *textArea)
    {
    	g_return_if_fail(fileName && textArea);
    	{
    		gchar *contents = NULL;
    		if(g_file_get_contents(fileName,&contents,NULL,NULL))
    		{
    			gchar *utf8 = NULL;
    		  GtkTextIter iter;
    		  GtkTextBuffer *textBuffer = NULL;
     
    			textBuffer = gtk_text_view_get_buffer(textArea);
    			gtk_text_buffer_get_iter_at_line(textBuffer,&iter,0);
    			utf8 = g_locale_to_utf8(contents,-1,NULL,NULL,NULL);
    			g_free (contents),contents = NULL;
    			gtk_text_buffer_insert(textBuffer,&iter,utf8,-1);
    			g_free (utf8),utf8 = NULL;
    		}
    		else
    		  printf("ERROR -> Can't open %s",fileName);
    	}
    }

  2. #2
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Points : 1 633
    Points
    1 633
    Par défaut
    Le prototype de
    void gsa_OpenFile(const gchar *fileName,GtkTextView *textArea) ne fait vraiment pas penser au prototype à utiliser pour un callback connecté à l'evt "clicked" d'un GtkButton.

  3. #3
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Points : 1 633
    Points
    1 633
    Par défaut
    Et gchar fileName ça définit effectivement un entier de type char, pas un pointeur auquel tu peux assigner NULL. Soit t'as fait une légère typo, soit il vaut mieux relire un peu ton bouquin de C

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    79
    Détails du profil
    Informations personnelles :
    Âge : 30
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 79
    Points : 63
    Points
    63
    Par défaut
    arf, j'ai oublier le * de fileName, après l'avoir rajouté, j'ai des erreurs GTK en plus, mais plus de warnings avec GCC .
    (gtk:10022): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkTextView'

    (gtk:10022): Gtk-CRITICAL **: gtk_text_view_get_buffer: assertion `GTK_IS_TEXT_VIEW (text_view)' failed

    (gtk:10022): Gtk-CRITICAL **: gtk_text_buffer_get_iter_at_line: assertion `GTK_IS_TEXT_BUFFER (buffer)' failed

    (gtk:10022): Gtk-CRITICAL **: gtk_text_buffer_insert: assertion `GTK_IS_TEXT_BUFFER (buffer)' failed

  5. #5
    Membre expérimenté
    Homme Profil pro
    Inscrit en
    Janvier 2005
    Messages
    1 259
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2005
    Messages : 1 259
    Points : 1 633
    Points
    1 633
    Par défaut
    Ces warnings là, c'est fort probablement dû au pb que j'évoquais dans mon premier msg.

Discussions similaires

  1. Réponses: 1
    Dernier message: 30/03/2007, 00h53
  2. GLib GObject WARNING
    Par j_p_g dans le forum wxPython
    Réponses: 1
    Dernier message: 19/03/2007, 19h41
  3. error: invalid conversion from `const wxChar*' to `CHAR*'
    Par barbarello dans le forum wxWidgets
    Réponses: 16
    Dernier message: 31/01/2006, 11h28
  4. invalid static_cast from type `void
    Par barbarello dans le forum Autres éditeurs
    Réponses: 1
    Dernier message: 04/01/2006, 12h04
  5. Réponses: 2
    Dernier message: 24/12/2005, 11h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo