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 :

erreur à l'écruiture dans un textview


Sujet :

GTK+ avec C & C++

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2012
    Messages
    114
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2012
    Messages : 114
    Points : 53
    Points
    53
    Par défaut erreur à l'écruiture dans un textview
    Bine le bonjour,
    je tente d'écrire du texte dans un textview:

    j'ai créé une fenetre avec des boutons et textview (et autres) depuis glade3,
    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
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Generated with glade 3.18.3 -->
    <interface>
      <requires lib="gtk+" version="3.12"/>
      <object class="GtkTextBuffer" id="textbuffer1"/>
      <object class="GtkWindow" id="MainWindow">
        <property name="can_focus">False</property>
        <child>
          <object class="GtkBox" id="box1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="orientation">vertical</property>
            <child>
              <object class="GtkMenuBar" id="menubar1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <child>
                  <object class="GtkMenuItem" id="menuitem1">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes">_Fichier</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu1">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem1">
                            <property name="label">gtk-new</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem2">
                            <property name="label">gtk-open</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem3">
                            <property name="label">gtk-save</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem4">
                            <property name="label">gtk-save-as</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem5">
                            <property name="label">gtk-quit</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem2">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes">É_dition</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu2">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem6">
                            <property name="label">gtk-cut</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem7">
                            <property name="label">gtk-copy</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem8">
                            <property name="label">gtk-paste</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem9">
                            <property name="label">gtk-delete</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem3">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes">_Affichage</property>
                    <property name="use_underline">True</property>
                  </object>
                </child>
                <child>
                  <object class="GtkMenuItem" id="menuitem4">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="label" translatable="yes">Aid_e</property>
                    <property name="use_underline">True</property>
                    <child type="submenu">
                      <object class="GtkMenu" id="menu3">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkImageMenuItem" id="imagemenuitem10">
                            <property name="label">gtk-about</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_underline">True</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkScrolledWindow" id="scrolledwindow1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="shadow_type">in</property>
                <child>
                  <object class="GtkViewport" id="viewport1">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <child>
                      <object class="GtkTextView" id="TextViewEtat">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="buffer">textbuffer1</property>
                      </object>
                    </child>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkGrid" id="grid1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <child>
                  <object class="GtkButton" id="ButtonRestart">
                    <property name="label" translatable="yes">Redémarrer</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="left_attach">2</property>
                    <property name="top_attach">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="ButtonStop">
                    <property name="label" translatable="yes">Eteindre</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                  </object>
                  <packing>
                    <property name="left_attach">3</property>
                    <property name="top_attach">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="BoutonTest">
                    <property name="label" translatable="yes">BoutonTest</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="relief">none</property>
                    <property name="xalign">0.44999998807907104</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">1</property>
                  </packing>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
                <child>
                  <placeholder/>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">2</property>
              </packing>
            </child>
            <child>
              <object class="GtkStatusbar" id="StatusBar">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="margin_left">10</property>
                <property name="margin_right">10</property>
                <property name="margin_start">10</property>
                <property name="margin_end">10</property>
                <property name="margin_top">6</property>
                <property name="margin_bottom">6</property>
                <property name="orientation">vertical</property>
                <property name="spacing">2</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">3</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
      <object class="GtkTextBuffer" id="textbuffer2"/>
    </interface>
    à l'exécution tout s'affiche comme prévu
    voici mon fichier main_gtk.cpp:
    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
    #include "main_gtk.h"
    #include "gtk_sig.h"
    #include <gtk/gtk.h>
     
      GtkWidget *BoutonTest = NULL;
      GtkWidget *TextViewEtat = NULL;
     
     
    int main_gtk(int argc, char *argv []) {
      GtkWidget *fenetre_principale = NULL;
      //GtkWidget *BoutonTest = NULL;
     
      GtkBuilder *builder = NULL;
      GError *error = NULL;
      gchar *filename = NULL;
      /* Initialisation de la librairie Gtk. */
      gtk_init(&argc, &argv);
     
      /* Ouverture du fichier Glade de la fenêtre principale */
      builder = gtk_builder_new();
     
      /* Création du chemin complet pour accéder au fichier test.glade. */
      /* g_build_filename(); construit le chemin complet en fonction du système */
      /* d'exploitation. ( / pour Linux et \ pour Windows) */
      filename =  g_build_filename ("test.glade", NULL);
     
      /* Chargement du fichier test.glade. */
      gtk_builder_add_from_file (builder, filename, &error);
      g_free (filename);
      if (error){
        gint code = error->code;
        g_printerr("%s\n", error->message);
        g_error_free (error);
        return code;
      }
     
      /* Récupération du pointeur de la fenêtre principale */
      fenetre_principale = GTK_WIDGET(gtk_builder_get_object (builder, "MainWindow"));
      BoutonTest = GTK_WIDGET(gtk_builder_get_object (builder, "BoutonTest"));
     
     
      /* Affectation du signal "destroy" à la fonction gtk_main_quit(); pour la */
      /* fermeture de la fenêtre. */
      g_signal_connect (G_OBJECT (fenetre_principale), "destroy", (GCallback)gtk_main_quit, NULL);
      g_signal_connect (G_OBJECT (BoutonTest), "clicked", (GCallback)click_BoutonTest, NULL);
     
      /* Affichage de la fenêtre principale. */
      gtk_widget_show_all (fenetre_principale);
     
      gtk_main();
     
      return 0;
    }
    et au clic du BoutonTest, je veux rtemplir le textview TextViewEtat:
    voici le fichier de la fonction liée au signal clicked
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include "gtk_sig.h"
    #include <gtk/gtk.h>
     
    extern GtkWidget *TextViewEtat;
     
     
    void click_BoutonTest(){
      //gtk_main_quit();
      GtkTextBuffer * buff;
      GtkWidget *view;
      view = gtk_text_view_new();
      buff = gtk_text_view_get_buffer (GTK_TEXT_VIEW (TextViewEtat));
      gtk_text_buffer_set_text (buff, "hello", -1);
    }
    et quand je clique sur le BoutonEtat, un message d'erreur apparait dans la console, et rien dans le TextViewEtat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Gtk-CRITICAL **:gtk_text_view_get_buffer: assertion 'GTK_IS_TEXT_VIEW (text_view)' failed 
    Gtk-CRITICAL **:gtk_text_buffer_set_text: assertion 'GTK_IS_TEXT_BUFFER (buffer)' failed
    Je ne comprends pas le problème.
    Par contre si je pointe sur un nouveau GtkWidget *view spécialement créé pour tester vers un autre text_view, rien ne s'affiche dans le text view puisqu'il n'est pas affiché, mais je n'ai aucune erreur dans la console ...

    DOnc pourquoi ne puis-je pointer vers mon TextViewEtat?
    Merci

  2. #2
    Modérateur

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2009
    Messages
    1 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 395
    Points : 2 002
    Points
    2 002
    Par défaut
    Bonjour,

    le problème est que tu ne respectes pas la signature du signal, son prototype. Ta callback est censée avoir des arguments en entrée et renvoyer des choses, et ça ne se devine pas. Tu dois lire la documentation pour savoir comment définir ta callback.
    Ici en l'occurence, pour le signal "clicked" d'un GtkButton:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    void click_BoutonTest (GtkButton *button, gpointer user_data)
    C'est vrai pour tous les signaux.

    Ensuite, ton TextViewEtat n'est jamais initialisé. Plutôt que d'utiliser une variable définie en extern, récupère le pointeur vers le widget dans ton mailn, et passe le comme argument user_data quand tu connectes les signal. Ainsi, tu le récupéreras directement dans le paramètre user_data de ta callback.
    Documentation officielle GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels par l'exemple (platform-demos):
    GTK (tous langages)

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2012
    Messages
    114
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2012
    Messages : 114
    Points : 53
    Points
    53
    Par défaut
    Bonjour liberforce,

    merci pour ta réponse, mais on ne joue pas dans la même catégorie, et je n'arrive pas à te suivre.

    Pour l'heure, je laisse tomber ce bout de code, pour démarrer sur des bases plus saines.

    Il me semble par exemple que je devrai plutôt bosser avec gtkmm comme librairie.

    Je dois aussi m'assurer que je bosse avec la version 3 de gtk+, et être sûr de consulter les docs adéquates.

    et trouver des tuto ou faq bien explicite en pas à pas, ou des exemples, pour mes premiers pas

    ensuite, j'attaque du code

    Merci

  4. #4
    Modérateur

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2009
    Messages
    1 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 395
    Points : 2 002
    Points
    2 002
    Par défaut
    Bonjour,

    bon, ça aurait été plus constructif de dire ce que tu n'as pas compris, j'aurais pu reformuler

    Pour ce qui est des exemples, tu as les démos de la platefome GNOME en plusieurs langages.
    https://developer.gnome.org/gnome-devel-demos/stable/
    Documentation officielle GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels GTK+ 3:
    GTK en C, GTK en Python

    Tutoriels par l'exemple (platform-demos):
    GTK (tous langages)

Discussions similaires

  1. Erreurs affichage d'un fichier dans un textview
    Par Selennad dans le forum GTK+ avec C & C++
    Réponses: 3
    Dernier message: 06/06/2008, 17h33
  2. Erreur compilation DLL dans Eelphi 6
    Par jakouz dans le forum Langage
    Réponses: 2
    Dernier message: 25/05/2005, 17h38
  3. [JSP]Erreur de syntaxe dans un tag <option select
    Par logica dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 03/05/2005, 15h33
  4. Erreur type interdit dans __property
    Par Neilos dans le forum C++Builder
    Réponses: 4
    Dernier message: 11/01/2005, 22h45
  5. [Servlet][Compilation] Erreur de compil dans code servlet
    Par gandalf_le_blanc dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 13/05/2004, 11h17

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