Bonjour a tous,
je viens de débuter avec gtk mais j'ai rencontre un probleme lors de la recuperation de deux champs de saisie.je suis là pour faire appel a vos expériences
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
 
  1 #include <stdlib.h>
  2 #include <gtk/gtk.h>
  3 
  4 struct _MainWindow
  5 {
  6     GtkWidget *fenetre_pr;
  7     GtkWidget *box_pr;
  8     GtkWidget *box_2;
  9     GtkWidget *but_continuer;
 10     GtkWidget *label_1;
 11     GtkWidget *radio1;
 12     GtkWidget *radio2;
 13     GtkWidget *radio3;
 14     GSList    *group;
 15 };
 16 typedef struct _MainWindow MainWindow;
 17 
 18 struct _Secondo
 19 {
 20 GtkWidget *fenetre_2;
 21 GtkWidget *box_2;
 22 GtkWidget *circuit;
 23 GtkWidget *trafric;
 24 };
 25 typedef struct _Secondo Secondo;
 26 
 27 //les prototypes de mes fonctions
 28   void OnDestroy(GtkWidget *pWidget, gpointer pData);
 29   void Afficher(GtkWidget *widget, gpointer data);
 30   void Resultat(GtkWidget *widget, gpointer data);
 31 
 32 
 33 int main(int argc, char **argv)
 34 {
 35 /* Initialisation de GTK+ */
 36     gtk_init(&argc, &argv);
 37 
 38 //initialisation 
 39    MainWindow *pApp; // pour les autres
 40    pApp = g_malloc(sizeof(MainWindow));
 41 
 42  //juste pour la fenetre
 43  pApp->fenetre_pr= gtk_window_new(GTK_WINDOW_TOPLEVEL);
 44  gtk_window_set_title (GTK_WINDOW(pApp->fenetre_pr), "Projet");
 45  gtk_window_set_position(GTK_WINDOW(pApp->fenetre_pr), GTK_WIN_POS_CENTER);
 46  gtk_window_set_default_size(GTK_WINDOW(pApp->fenetre_pr), 620, 400);
 48 
 49 //pour le label
 50   pApp->label_1=gtk_label_new("<b>Bienvenue</b>");
 51   gtk_label_set_use_markup(GTK_LABEL(pApp->label_1), TRUE);
 52   gtk_label_set_justify (GTK_LABEL(pApp->label_1), GTK_JUSTIFY_CENTER);
 53 
 54 //pour le button
 55  pApp->but_continuer = gtk_button_new_with_label("Continuer");
 56 
 57 //creation des button radio
 58  pApp->radio1 = gtk_radio_button_new_with_label(NULL, "calcul de proba de perte");
 59  pApp->group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(pApp->radio1));
 60  pApp->radio2 = gtk_radio_button_new_with_label(pApp->group, "calcul de je ne sais quoi");
 61 
 62 // le box secondair (horizontal)
 63  pApp->box_2 = gtk_hbox_new(TRUE, 0);
 64 
 65 // le box principal
 66  pApp-> box_pr = gtk_vbox_new(TRUE, 0);
 67 
 68 //ajout du box principal dans la fenetre principal, ce box va contenir les autres widget
 69  gtk_container_add(GTK_CONTAINER(pApp->fenetre_pr),pApp-> box_pr);
 70 
 71 //ajout des button dans le box horizontal
 72  gtk_box_pack_start(GTK_BOX(pApp->box_2), pApp->radio1, TRUE, FALSE, 0);
 73  gtk_box_pack_start(GTK_BOX(pApp->box_2), pApp->radio2, TRUE, FALSE, 0);
 74 
 75  //ajout des autres widget dans le box principal
 76  gtk_box_pack_start(GTK_BOX(pApp->box_pr), pApp->label_1, TRUE, FALSE, 0);
 77  gtk_box_pack_start(GTK_BOX(pApp->box_pr), pApp->box_2, TRUE, FALSE, 0);
 78  gtk_box_pack_start(GTK_BOX(pApp->box_pr),pApp-> but_continuer, TRUE, FALSE, 0);
 79 
 80 //appel des fonctions evenementielles
 81  g_signal_connect(G_OBJECT(pApp->fenetre_pr), "destroy", G_CALLBACK(OnDestroy), NULL);
 82 
 83  g_signal_connect(G_OBJECT(GTK_BUTTON(pApp->but_continuer)), "clicked", G_CALLBACK(Afficher),(gpointer*) pApp);
 84 
 85  gtk_widget_show_all(pApp->fenetre_pr);
 86 //  Demarrage de la boucle evenementielle 
 87     gtk_main();
 88 
 89 //liberation de la memoir allouee
 90 g_free(pApp);
 91 
 92     return EXIT_SUCCESS;
 93 }
 94 
void OnDestroy(GtkWidget *pWidget, gpointer pData)
 96  {
 97     /* Arret de la boucle evenementielle */
 98     gtk_main_quit();
 99  }
100 
101 void Afficher(GtkButton *widget, gpointer data)
102 {
103     MainWindow *pApp;
104     GtkWidget *box_horiz=NULL;
105     GtkWidget *box_horiz2=NULL;
106     GtkWidget *box_horiz3=NULL;
107     GtkWidget *but_resultat;
108     GtkWidget *label_circuit=NULL;
109     GtkWidget *label_trafric=NULL;
110     GtkWidget *label_bourage=NULL;
111     GtkWidget *label_bourage2=NULL;
112 
113     pApp = (MainWindow*) data; // recupretion de data
114     const gchar *label_test;
115     Secondo *proba;
116 
117    //allocation de la memoire
118         proba = g_malloc(sizeof(Secondo));
119 
120         // Le bouton radio1 est il selectionne ?
121         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pApp->radio1)))
122         {
123 
124                        //oui donc on ouvre une nouvelle fenetre
125                       //juste pour la fenetre secondaire
126                       proba->fenetre_2= gtk_window_new(GTK_WINDOW_TOPLEVEL);
127                       gtk_window_set_title (GTK_WINDOW(proba->fenetre_2), "calcul de probalite de perte d'apres Erlang");
128                       gtk_window_set_position(GTK_WINDOW(proba->fenetre_2), GTK_WIN_POS_NONE);
129                       gtk_window_set_default_size(GTK_WINDOW(proba->fenetre_2), 420, 300);
130 
131      // creation des widget 
132           proba->box_2=gtk_vbox_new(TRUE, 0);
133            box_horiz2=gtk_hbox_new(TRUE, 0);
134            box_horiz= gtk_hbox_new(TRUE, 0);
135            box_horiz3= gtk_hbox_new(TRUE, 0);
136           proba->circuit = gtk_entry_new();
137           proba->trafric= gtk_entry_new();
138            label_circuit= gtk_label_new("circuit  :");
139            label_trafric= gtk_label_new("trafric  :");
140            label_bourage=gtk_label_new("     ");
141            label_bourage2=gtk_label_new("     ");
142            but_resultat = gtk_button_new_with_label("Resultat");
 143 
144           // ajout du label circuit et la zone de saisie du nbre de circuit dans le box horizontal
145            gtk_box_pack_start(GTK_BOX(box_horiz), label_circuit, TRUE, FALSE, 0);
146            gtk_box_pack_start(GTK_BOX(box_horiz), proba->circuit, TRUE, FALSE, 0);
147 
148           // ------------||-------------------||---------------nbre de trafric----||---horizontal2
149            gtk_box_pack_start(GTK_BOX(box_horiz2), label_trafric, TRUE, FALSE, 0);
150            gtk_box_pack_start(GTK_BOX(box_horiz2),proba->trafric, TRUE, FALSE, 0);
151 
152          //ajout pour le box horizontal 3
153            gtk_box_pack_start(GTK_BOX(box_horiz3), label_bourage, TRUE, FALSE, 0);
154            gtk_box_pack_start(GTK_BOX(box_horiz3), label_bourage2, TRUE, FALSE, 0);
155            gtk_box_pack_start(GTK_BOX(box_horiz3), but_resultat, TRUE, FALSE, 0);
156 
157          // ajout des box horizontal dans le box principale(vertical )  
158            gtk_box_pack_start(GTK_BOX(proba->box_2), box_horiz, TRUE, FALSE, 0);
159            gtk_box_pack_start(GTK_BOX(proba->box_2), box_horiz2, TRUE, FALSE, 0);
160            gtk_box_pack_start(GTK_BOX(proba->box_2), box_horiz3, TRUE, FALSE, 0);
161 
162           //ajout du box principal dans la fenetre principal, ce box a contenu les autres widget
163            gtk_container_add(GTK_CONTAINER(proba->fenetre_2),proba->box_2);
164            gtk_widget_show_all(proba->fenetre_2);
165 
166    g_signal_connect(G_OBJECT(GTK_BUTTON(but_resultat)), "clicked", G_CALLBACK(Resultat),(gpointer*) proba);
167         }
168         else
169         {
170 
171         }
172          g_free(proba);
173 }
174 
175 void Resultat(GtkButton *widget, gpointer data)
176    {
177    Secondo * proba;
178   proba =(Secondo*) data; //recuperation de data
179 
180    const gchar* data_temp_cir=NULL;
181    const gchar* data_temp_traf=NULL;
182    data_temp_cir=gtk_entry_get_text(GTK_ENTRY(proba->circuit));
183    data_temp_traf=gtk_entry_get_text(GTK_ENTRY(proba->trafric));
}
le code passe a la compilation mais des que je clique sur le bouton résultat
situé sur la fenêtre secondaire,j'ai un le message "Erreur de segmentation"
. en cherchant l'origine du probleme j'ai la ligne 182 en commentaire et le message d'erreur change "(GraphDef.exe:3792): Gtk-CRITICAL **: gtk_entry_get_text: assertion `GTK_IS_ENTRY (entry)' failed".C'est bizar 182 et 183 sont presque pareil.je sais que c'est parce que j'ai mal utilise un pointeur mais je vois vraiment pas.
pouvez vous dire d'ou vient l'erreur?