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+ Discussion :

Gtk - Warning: Could Not Find Signal Handler


Sujet :

GTK+

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut Gtk - Warning: Could Not Find Signal Handler
    Bonjour tout le monde.
    Je suis étudiant en cycle de prepa intégré dans une école d'ingénieur en informatique.
    Je cherche à faire une interface pour un programme et j'ai donc choisi d'utiliser la bibliothèque gtk.
    C'est cette année que je découvre linux, code blocks, les makefiles ou les commandes de compilation qu'il faut ajouter dans les build options...blablabla
    Donc peut être que mon problème viens de là aussi et si vous avez des remarques à me faire sur n'importe quoi allez y, je suis là pour apprendre.^^
    Merci d'avance à vous.

    Voici mes trois fichiers sources que j'utilise:
    callback.ccallback.hmain.c

    Voilà mes paramètres de compilations:
    Dans build options -> debug -> compiler settings -> other options j'ai:
    `pkg-config --cflags gtk+-2.0`
    `gcc -c main.c -o main.o $(pkg-config --cflags gtk+-2.0 gmodule-2.0)`
    `gcc -c callback.c -o callback.o $(pkg-config --cflags gtk+-2.0 gmodule-2.0)`
    `gcc -o main main.o callback.o $(pkg-config --libs gtk+-2.0 gmodule-2.0)`
    Dans build options -> debug -> linker settings -> other linker options j'ai:
    `pkg-config --libs gtk+-2.0`
    Et enfin voilà les détails de mon fichier xml:

    Code xml : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <interface>
      <requires lib="gtk+" version="2.24"/>
      <!-- interface-naming-policy project-wide -->
      <object class="GtkWindow" id="main_window">
        <property name="can_focus">False</property>
        <property name="border_width">6</property>
        <property name="title" translatable="yes">VOLCARM</property>
        <property name="window_position">center</property>
        <property name="default_width">1500</property>
        <property name="default_height">800</property>
        <signal name="destroy" handler="gtk_main_quit" swapped="no"/>
        <child>
          <object class="GtkVBox" id="vbox">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkStatusbar" id="statusbar">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="spacing">2</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="pack_type">end</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkHBox" id="hbox">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <child>
                  <object class="GtkScrolledWindow" id="scrolledwindow1">
                    <property name="width_request">620</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="hscrollbar_policy">automatic</property>
                    <property name="vscrollbar_policy">automatic</property>
                    <child>
                      <object class="GtkViewport" id="viewport1">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkImage" id="image">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="stock">gtk-missing-image</property>
                            <property name="icon-size">6</property>
                            <signal name="button-press-event" handler="cb_loadimage" swapped="no"/>
                          </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="scrolledwindow2">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="hscrollbar_policy">automatic</property>
                    <property name="vscrollbar_policy">automatic</property>
                    <child>
                      <object class="GtkViewport" id="viewport2">
                        <property name="visible">True</property>
                        <property name="can_focus">False</property>
                        <child>
                          <object class="GtkTextView" id="textview">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                          </object>
                        </child>
                      </object>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">True</property>
                    <property name="fill">True</property>
                    <property name="position">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="pack_type">end</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>

  2. #2
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Bonjour.

    Tout d'abord, lorsque tu affiches du code encadre-le avec les balises "code" prévues (le dièse dans les icônes au dessus de l'éditeur de post). C'est plus facile à lire pour nous, pauvres lecteurs que nous sommes .

    Pour ce qui est de ton code il fonctionne correctement chez moi ! Je suppose que le problème peut provenir lors de l'assemblage de ton application. Il manque semble-t-il cette option :
    • `pkg-config gmodule-2.0 --libs`


    Deux petites remarques pour finir.
    1. Tu alloues dans le tas data. Je n'en vois pas l'utilité ici. Puisque cette donnée est valide tout au long du processus, tu peux déclarer simplement une variable du type OCRData et propager son pointeur à tes fonctions callback.
    2. Tu détruis builder avant la fin de ton processus. Par expérience j'ai tendance à propager ce pointeur dans mes fonctions callback. Il arrive très souvent d'avoir besoin d'accéder à un widget quelconque de ton interface. Je le détruirais donc à la sortie de la boucle gtkmain();. C'est un point de vue .

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    J'ai décidé de reprendre le projet à zéro sur vim. Pour l'insant je suis ce tutoriel: http://gerald3d.developpez.com/tutoriels/gtk/glade3/

    Cependant, j'ai un problème de compilation, sûrement lié à mon Makefile. J'ai cette erreur:
    gcc -o main.o -c main.c -Wall -Werror -Wextra -std=c99 -O2 `pkg-config --libs gmodule-2.0` `pkg-config --cflags gtk+-2.0`
    gcc -lm `pkg-config --libs gmodule-2.0` `pkg-config --libs gtk+-2.0` main.o -o main
    main.o: dans la fonction « main »:
    main.c:(.text.startup+0x20): référence indéfinie vers « gtk_init »
    main.c:(.text.startup+0x25): référence indéfinie vers « gtk_builder_new »
    main.c:(.text.startup+0x36): référence indéfinie vers « g_build_filename »
    main.c:(.text.startup+0x49): référence indéfinie vers « gtk_builder_add_from_file »
    main.c:(.text.startup+0x51): référence indéfinie vers « g_free »
    main.c:(.text.startup+0x6e): référence indéfinie vers « g_printerr »
    main.c:(.text.startup+0x78): référence indéfinie vers « g_error_free »
    main.c:(.text.startup+0x86): référence indéfinie vers « gtk_widget_get_type »
    main.c:(.text.startup+0x96): référence indéfinie vers « gtk_builder_get_object »
    main.c:(.text.startup+0xa1): référence indéfinie vers « g_type_check_instance_cast »
    main.c:(.text.startup+0xb1): référence indéfinie vers « g_type_check_instance_cast »
    main.c:(.text.startup+0xbe): référence indéfinie vers « gtk_main_quit »
    main.c:(.text.startup+0xcb): référence indéfinie vers « g_signal_connect_data »
    main.c:(.text.startup+0xd3): référence indéfinie vers « gtk_widget_show_all »
    main.c:(.text.startup+0xd8): référence indéfinie vers « gtk_main »
    collect2: error: ld returned 1 exit status
    make: *** [main] Erreur 1
    Voici mon makefile:
    Code makefile : 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
    CC=gcc
    CFLAGS=-Wall -Werror -Wextra -std=c99 -O2 `pkg-config --libs gmodule-2.0` `pkg-config --cflags gtk+-2.0`
    LDFLAGS=-lm `pkg-config --libs gmodule-2.0` `pkg-config --libs gtk+-2.0`
    EXEC=test
     
    all: $(EXEC)
     
    test: main.o
            $(CC) -o $@ $^ $(LDFLAGS)
     
    main.o: main.c
            $(CC) -o $@ -c $< $(CFLAGS)
     
    clean:
            rm -rf *.o
     
    mrproper: clean
            rm -rf $(EXEC)

    Voici le fichier source:
    main.c

    Et mon fichier glade:
    Code xml : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Generated with glade 3.16.1 -->
    <interface>
      <requires lib="gtk+" version="3.10"/>
      <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="GtkMenuButton" id="menubutton1">
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <child>
                  <placeholder/>
                </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="GtkTextView" id="TextView">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</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_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">2</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>

    Merci d'avance si vous avez une solution.^^

  4. #4
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Je vois que tu compiles avec Gtk+2.0. Est-ce bien cette version qui est installée sur ta machine ? La version courante est la 3.14.5.

  5. #5
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    En fait j'utilise la version 3.16, c'est écrit dans le fichier glade. Et je viens de lire que celà requiert la version 3.10 au moins... D'accord je vois je vois. Il faut que je fasse quoi dans ce cas? Enfin, je dois écrire quoi exactement?

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Ah en fait j'ai vérifié, c'est la version 2.0 qui est installée sur mon ordi. Il faut donc que j'installe une version supérieur ou égale à la 3.10. D'accord, et ensuite qu'est ce que je dois écrire dans les options de lien et les options de compilation?

  7. #7
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Je viens d'installer gtk+3 en utilisant la commande: sudo apt-get install gtk+3
    Et j'ai remplacé tous les "2.0" de mon Makefile (qui est plus haut dans le forum) par "3.10"
    Cependant j'ai cette erreur:
    gcc -o main.o -c main.c -Wall -Werror -Wextra -std=c99 -O2 `pkg-config --libs gmodule-3.10` `pkg-config --cflags gtk+-3.10`
    Package gmodule-3.10 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gmodule-3.10.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gmodule-3.10' found
    Package gtk+-3.10 was not found in the pkg-config search path.
    Perhaps you should add the directory containing `gtk+-3.10.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'gtk+-3.10' found
    main.c:3:21: fatal error: gtk/gtk.h: Aucun fichier ou dossier de ce type
    #include <gtk/gtk.h>
    ^
    compilation terminated.
    make: *** [main.o] Erreur 1

    Sauriez vous d'où viens le problème?

  8. #8
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Bon il y a deux choses à faire :

    1. Installer en plus de la bibliothèque Gtk+3.0 le paquet de développement (sous Débian le paquet se termine par -dev). Ce paquet installe les fichiers d'entête (les .h) pour permettre l'utilisation de la bibliothèque lors de la compilation.
    2. Modifier les options de compilation de la sorte : `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`


    Tu peux lancer directement dans une console l'option de compilation de Gtk+ pour voir si ca marche ou pas : pkg-config --cflags gtk+-3.0

    Tu devrais avoir ce genre de réponse :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include

  9. #9
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Bonsoir, alors mon problème persiste.
    J'ai bien installé Gtk+3.0 à l'aide de ces deux commandes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sudo apt-get install libgtk-3-dev
    et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    sudo apt-get install gtk+3.
    J'ai lancé 'pkg-config --cflags gtk+-3.0' dans le terminal et j'ai bien eu ceci comme réponse:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12
    .

    J'ai également modifié mon Makefile, c'est celui ci désormais:
    Code Makefile : 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
    CC=gcc
    CFLAGS=-Wall -Werror -Wextra -std=c99 -O2 `pkg-config --cflags gtk+-3.0`
    LDFLAGS=-lm `pkg-config --libs gtk+-3.0`
    EXEC=test
     
    all: $(EXEC)
     
    test: main.o
            $(CC) -o $@ $^ $(LDFLAGS)
     
    main.o: main.c
            $(CC) -o $@ -c $< $(CFLAGS)
     
    clean:
            rm -rf *.o
     
    mrproper: clean
            rm -rf $(EXEC)

    Et pourtant, quand je compile mon programme, j'ai cette erreur:
    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
    gcc -o main.o -c main.c -Wall -Werror -Wextra -std=c99 -O2 `pkg-config --cflags gtk+-3.0`
    gcc -lm `pkg-config --libs gtk+-3.0`  main.o   -o main
    main.o: dans la fonction « main »:
    main.c:(.text.startup+0x20): référence indéfinie vers « gtk_init »
    main.c:(.text.startup+0x25): référence indéfinie vers « gtk_builder_new »
    main.c:(.text.startup+0x36): référence indéfinie vers « g_build_filename »
    main.c:(.text.startup+0x49): référence indéfinie vers « gtk_builder_add_from_file »
    main.c:(.text.startup+0x51): référence indéfinie vers « g_free »
    main.c:(.text.startup+0x6e): référence indéfinie vers « g_printerr »
    main.c:(.text.startup+0x78): référence indéfinie vers « g_error_free »
    main.c:(.text.startup+0x86): référence indéfinie vers « gtk_widget_get_type »
    main.c:(.text.startup+0x96): référence indéfinie vers « gtk_builder_get_object »
    main.c:(.text.startup+0xa1): référence indéfinie vers « g_type_check_instance_cast »
    main.c:(.text.startup+0xb1): référence indéfinie vers « g_type_check_instance_cast »
    main.c:(.text.startup+0xbe): référence indéfinie vers « gtk_main_quit »
    main.c:(.text.startup+0xcb): référence indéfinie vers « g_signal_connect_data »
    main.c:(.text.startup+0xd3): référence indéfinie vers « gtk_widget_show_all »
    main.c:(.text.startup+0xd8): référence indéfinie vers « gtk_main »
    collect2: error: ld returned 1 exit status
    make: *** [main] Erreur 1
    Quel est donc le problème?

    Je précise que mon seul fichier source est toujours:
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <gtk/gtk.h>
     
    #define UI_FILE "test.glade"
     
    int
    main(int argc, char *argv [])
    {
            GtkWidget *fenetre_principale = 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 (UI_FILE, 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"));
     
            /* 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);
     
            /* Affichage de la fenêtre principale. */
            gtk_widget_show_all (fenetre_principale);
     
            gtk_main();
     
            return 0;
    }
    Et que mon fichier glade est bien toujours:
    Code xml : 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
    <?xml version="1.0" encoding="UTF-8"?>
    <interface>
      <requires lib="gtk+" version="2.24"/>
      <!-- interface-naming-policy project-wide -->
      <object class="GtkWindow" id="MainWindow">
        <property name="can_focus">False</property>
        <child>
          <object class="GtkVBox" id="vbox1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkImage" id="Image">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="stock">gtk-missing-image</property>
              </object>
              <packing>
                <property name="expand">True</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="hscrollbar_policy">automatic</property>
                <property name="vscrollbar_policy">automatic</property>
                <child>
                  <object class="GtkTextView" id="TextView">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                  </object>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkStatusbar" id="StatusBar">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="spacing">2</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">2</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>

  10. #10
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Bon chez moi ton code compile correctement avec ton Makefile. La seule chose que j'ai modifié c'est le changement des espaces en tabulation des lignes 10, 13, 16 et 19. Àprès ce problème d'espace apparaît peut-être lors du copier/coller dans le forum...

    Résultat de la compilation dans une console :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    gerald@debian:~/test$ make
    gcc -o main.o -c main.c -Wall -Werror -Wextra -std=c99 -O2 `pkg-config --cflags gtk+-3.0`
    gcc -o test main.o -lm `pkg-config --libs gtk+-3.0`
    gerald@debian:~/test$
    Pour ma part j'ai d'installé :
    • libgtk-3.0
    • libgtk-3-dev
    • libglib2.0-0
    • libglib2.0-dev
    • ...

    Pour les autres librairies (GdkPixbuf et autres...) elles sont annexes et devraient d'ailleurs s'installer d'elles-mêmes.

  11. #11
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Bonjour,
    J'ai enfin pu régler mon problème, il venait de mon makefile, ce makefile fonctionne parfaitement avec.

    J'ai donc pu avancer sur le tutoriel de Gérald: http://gerald3d.developpez.com/tutoriels/gtk/glade3/

    Je suis bloqué à la dernière étape. Celle de la création de "AboutWindow". J'ai tout suivi jusqu'à la fin, j'ai compilé. J'ai lancé le programme, il s'ouvre parfaitement bien. Et, quand je clique sur Aide puis A propos, rien ne se passe. La fenêtre ne s'ouvre pas.
    Après recherche, j'ai conclu que le problème provenait surement du fichier glade, aurais-je raté un réglage important?
    Mais je reste cependant ouvert à toute proposition. Merci.

    Voici donc mon Makefile:

    Code Makefile : 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
    CC=clang
     
    CPPFLAGS= `pkg-config --cflags gtk+-3.0`
    CFLAGS= -Wall -Wextra -std=c99 -O2
    LDFLAGS=
    LDLIBS= `pkg-config --libs gtk+-3.0` `pkg-config gmodule-2.0 --libs`
     
    SRC= main.c
    OBJ= ${SRC:.c=.o}
     
    all: main
     
    main: ${OBJ} -lm
     
    clean:
    	rm -f *~ *.o
     
    # END

    Mon Code Source:

    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include "gtk/gtk.h"
     
    #define UI_FILE "Volcarm_OCR.glade"
     
    typedef struct
        {
          GtkBuilder *builder;
          gpointer user_data;
        } SGlobalData;
     
    void callback_about (GtkMenuItem *menuitem, gpointer user_data);
     
    int 
    main(int argc, char *argv []) 
    { 
    	GtkWidget *fenetre_principale = NULL;
            SGlobalData data;
            GError *error = NULL;
            gchar *filename = NULL;
            /* Initialisation de la bibliothèque Gtk. */
            gtk_init(&argc, &argv);
     
            /* Ouverture du fichier Glade de la fenêtre principale */ 
            data.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 (UI_FILE, NULL); 
     
            /* Chargement du fichier Volcarm_OCR.glade. */ 
            gtk_builder_add_from_file (data.builder, filename, &error); 
            g_free (filename); 
            if (error) 
            { 
         		gint code = error->code; 
            	g_printerr("%s\n", error->message); 
            	g_error_free (error); 
            	return code; 
            } 
     
            /* Affectation des signaux de l'interface aux différents CallBacks. */
            gtk_builder_connect_signals (data.builder, &data);
     
            /* Récupération du pointeur de la fenêtre principale */
          	fenetre_principale = GTK_WIDGET(gtk_builder_get_object (data.builder, "MainWindow"));
     
            /* Affichage de la fenêtre principale. */ 
            gtk_widget_show_all (fenetre_principale); 
     
            gtk_main();
     
    	return 0;
    }
     
    void
          callback_about (GtkMenuItem *menuitem, gpointer user_data)
          {
            /* Transtypage du pointeur user_data pour récupérer nos données. */
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *dialog = NULL;
     
            /* Récupération de la fenêtre "AboutWindow". */
            dialog =  GTK_WIDGET (gtk_builder_get_object (data->builder, "AboutWindow"));
            gtk_dialog_run (GTK_DIALOG (dialog));
     
            /* On cache la fenêtre de dialogue. Si on la détruisait le prochain appel */
            /* à ce callback provoquerait un segdefault! */
            gtk_widget_hide (dialog);
          }
    Et mon fichier glade:

    Code xml : 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
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Generated with glade 3.16.1 -->
    <interface>
      <requires lib="gtk+" version="3.10"/>
      <object class="GtkWindow" id="MainWindow">
        <property name="can_focus">False</property>
        <property name="margin_left">3</property>
        <property name="margin_right">3</property>
        <property name="margin_top">3</property>
        <property name="margin_bottom">3</property>
        <property name="title" translatable="yes">VOLCARM OCR</property>
        <property name="default_width">1200</property>
        <property name="default_height">720</property>
        <child>
          <object class="GtkBox" id="VerticalBox">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="orientation">vertical</property>
            <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_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">True</property>
                <property name="pack_type">end</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkBox" id="HorizontalBox">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <child>
                  <object class="GtkImage" id="Image">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="stock">gtk-missing-image</property>
                  </object>
                  <packing>
                    <property name="expand">True</property>
                    <property name="fill">True</property>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkGrid" id="GridButtons">
                    <property name="visible">True</property>
                    <property name="can_focus">False</property>
                    <property name="valign">center</property>
                    <child>
                      <object class="GtkButton" id="ButtonGrayScale">
                        <property name="label" translatable="yes">Grayscale</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">0</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkButton" id="ButtonBinarize">
                        <property name="label" translatable="yes">Binarization</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">1</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkButton" id="ButtonBlock">
                        <property name="label" translatable="yes">Block Detection</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">2</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkButton" id="ButtonLine">
                        <property name="label" translatable="yes">Line Detection</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">3</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkButton" id="ButtonCharacter">
                        <property name="label" translatable="yes">Character Detection</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">4</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                    <child>
                      <object class="GtkButton" id="ButtonNeuronal">
                        <property name="label" translatable="yes">Neuronal Network</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                      </object>
                      <packing>
                        <property name="left_attach">0</property>
                        <property name="top_attach">5</property>
                        <property name="width">1</property>
                        <property name="height">1</property>
                      </packing>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">False</property>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkScrolledWindow" id="ScrolledWindow">
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="shadow_type">in</property>
                    <child>
                      <object class="GtkTextView" id="TextView">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                      </object>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">True</property>
                    <property name="fill">True</property>
                    <property name="position">2</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>
                <property name="fill">True</property>
                <property name="pack_type">end</property>
                <property name="position">1</property>
              </packing>
            </child>
            <child>
              <object class="GtkGrid" id="GridShortcut">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="halign">start</property>
                <property name="valign">start</property>
                <property name="hexpand">False</property>
                <property name="vexpand">False</property>
                <child>
                  <object class="GtkButton" id="ButtonImage">
                    <property name="label">gtk-add</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="use_stock">True</property>
                    <property name="always_show_image">True</property>
                  </object>
                  <packing>
                    <property name="left_attach">0</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkButton" id="ButtonHelp">
                    <property name="label">gtk-help</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">True</property>
                    <property name="use_stock">True</property>
                    <property name="always_show_image">True</property>
                  </object>
                  <packing>
                    <property name="left_attach">1</property>
                    <property name="top_attach">0</property>
                    <property name="width">1</property>
                    <property name="height">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="pack_type">end</property>
                <property name="position">2</property>
              </packing>
            </child>
            <child>
              <object class="GtkMenuBar" id="MenuBar">
                <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="Item1">
                            <property name="label">gtk-add</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkSeparatorMenuItem" id="Separator1">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item2">
                            <property name="label">gtk-save-as</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkSeparatorMenuItem" id="Separator2">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item3">
                            <property name="label">gtk-quit</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</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="Item4">
                            <property name="label">gtk-cut</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item5">
                            <property name="label">gtk-copy</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item6">
                            <property name="label">gtk-paste</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item7">
                            <property name="label">gtk-delete</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</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">Aide</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="Item8">
                            <property name="label">gtk-help</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="use_stock">True</property>
                          </object>
                        </child>
                        <child>
                          <object class="GtkImageMenuItem" id="Item9">
                            <property name="label">gtk-about</property>
                            <property name="visible">True</property>
                            <property name="can_focus">False</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="pack_type">end</property>
                <property name="position">3</property>
              </packing>
            </child>
          </object>
        </child>
      </object>
    </interface>

    Merci d'avance pour votre aide.

  12. #12
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Ligne 4 tu écris #include "gtk/gtk.h". Ce n'est pas correcte même si ici ca fonctionne. Il faut des <> en lieu et place des "".

    Pour ton problème de fenêtre plus précisément tu demandes de récupérer le pointeur sur la fenêtre "AboutWindow" ligne 67. Mais je ne vois nulle part de fenêtre "AboutWindow" dans ton fichier glade. Reprends à partir d'ici dans le tuto. Tu as du oublier une étape .

  13. #13
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Effectivement mon problème venait de mon fichier. Si j'oublie de faire un "Ctrl + S" après avoir modifier le fichier glade, c'est un peu normal que ça ne marche pas après!lol
    J'ai donc réussi à le faire.
    Maintenant, je souhaite finir mon inteface en connectant tous mes boutons aux differents callback.
    J'ai commencé par celui dans "fichier --> QUITTER". J'ai pu le faire, mais j'aimerais savoir si c'est la bonne façon.

    Ma fonction callback_quit est écrite ainsi:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void callback_quit(GtkMenuItem *menuitem, gpointer user_data)
    {
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *MainWindow = NULL;
     
            MainWindow = GTK_WIDGET (gtk_builder_get_object (data->builder, "MainWindow"));
            //g_signal_connect (G_OBJECT (MainWindow), "clicked", (GCallback)gtk_main_quit, NULL);
     
            gtk_widget_destroy(MainWindow);
            gtk_main_quit();
    }
    Et aussi, pour la compilation, j'ai retiré le Werror dans mon makefile mais pour rendre mon projet je vais devoir le remettre. Comment gérer mes warnings unused parameter 'menuitem' ??

  14. #14
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Citation Envoyé par shumprevers Voir le message
    Effectivement mon problème venait de mon fichier. Si j'oublie de faire un "Ctrl + S" après avoir modifier le fichier glade, c'est un peu normal que ça ne marche pas après!lol
    J'ai donc réussi à le faire.
    Je me pose une question au vu de ce que tu écris. Tu n'utilises pas le logiciel Glade pour créer ton fichier .glade ? Ou alors j'ai mal interprété ta réponse.

    Maintenant, je souhaite finir mon inteface en connectant tous mes boutons aux differents callback.
    J'ai commencé par celui dans "fichier --> QUITTER". J'ai pu le faire, mais j'aimerais savoir si c'est la bonne façon.

    Ma fonction callback_quit est écrite ainsi:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    void callback_quit(GtkMenuItem *menuitem, gpointer user_data)
    {
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *MainWindow = NULL;
     
            MainWindow = GTK_WIDGET (gtk_builder_get_object (data->builder, "MainWindow"));
            //g_signal_connect (G_OBJECT (MainWindow), "clicked", (GCallback)gtk_main_quit, NULL);
     
            gtk_widget_destroy(MainWindow);
            gtk_main_quit();
    }
    Oui pourquoi pas. Maintenant la fonction gtk_main_quit(); va naturellement détruire tous les widgets. Donc on pourrait faire le plus court possible ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void callback_quit(GtkMenuItem *menuitem, gpointer user_data)
    {
      gtk_main_quit();
    }
    Ceci dit l'intérêt de disposer d'un callback pour quitter est de permettre la gestion des sauvegardes non effectuées par exemple.

    Et aussi, pour la compilation, j'ai retiré le Werror dans mon makefile mais pour rendre mon projet je vais devoir le remettre. Comment gérer mes warnings unused parameter 'menuitem' ??
    Puisque tu as un warning sur la non utilisation d'une variable, utilises-la même si c'est pour rien faire. Ce n'est pas très joli mais tu élimines sans risque les hurlements du compilo . Tu peux écrire ceci par exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    // Inutile mais supprime le -Werror du compilateur
    menuitem = menuitem;

    [EDIT]
    Pendant que j'y suis tu ne gères pas encore la fermeture de ton application par la croix de la fenêtre principale. Ca provoque bien la fermeture de la fenêtre mais pas l'arrêt de l'application. Il te faut donc connecter aussi le signal "delete-event" de MainWindow.

  15. #15
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Ah, effectivement, c'est mieux de faire une ligne de code pour ça!
    Heu oui je pense que tu as mal interprêté, j'utilise toujours glade, juste que j'avais pas enregistrer mes modifications avant de quitter le programme, du coup il n'y avais pas la boite de dialogue about.

    Ma question maintenant est comment configurer le bouton "ajouter" pour qu'il me permette d'aller sélectionner une image sur le disque dur et l'afficher à gauche dans l'emplacement prévu? Je ne vois pas du tout comment le faire...

  16. #16
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Je viens d'éditer mon précédent message (à la fin de celui-ci).

    Pour ton bouton "ajouter", tu crées un callback associé à l'évènement "clicked". Je pense que maintenant ceci n'a plus de secret pour toi.

    Dans le callback tu peux utiliser un GtkFileChooserDialog pour créer le sélectionneur de fichier. Histoire de faire encore plus propre tu peux toujours créer ce GtkFileChooserDialog dans ton fichier glade et appeler cette fenêtre comme tu l'as fait pour le AboutDialog.

    Consultes la documentation du widget GtkFileChooserDialog pour voir comment ca s'utilise.

    Remarque : si ce n'est pas encore fait je t'invite à installer DevHelp sur ta machine. Ca te permettra d'accéder à toute la documentation Gtk+ en local (il y a un package pour la doc Gtk+). L'avantage est que tu peux la consulter en local bien sûr et qu'elle est toujours à jour via les MAJ de ta distribution.

  17. #17
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Bonjour, et bien j'ai réussi à afficher l'image. Quand on clique sur le bouton ajouter, on va jusqu'à retrouver le fichier dans le disque dur, puis on a la possibilité de cliquer sur valider ou sur cancel. Valider pour l'afficher et cancel pour annuler bien évidemment. J'ai Donc 3 callback. Est ce que c'est la meilleure façon de le faire? Des conseils?
    Voici les callbacks:
    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
     
    void callback_add(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            gint res;
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *add = NULL;
     
            add=  GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
            res = gtk_dialog_run (GTK_DIALOG (add));
    }
     
    void callback_validate(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *chooserdialog = NULL;
            chooserdialog=GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
     
            char *filename;
            GtkFileChooser *chooser = GTK_FILE_CHOOSER(chooserdialog);
            filename = gtk_file_chooser_get_filename(chooser);
     
            //affichage de l'image
            GtkImage *image = GTK_IMAGE(gtk_builder_get_object(data->builder,"Image"));
            gtk_image_set_from_file (image,filename);
     
            gtk_widget_hide(chooserdialog);
    }
     
    void callback_cancel(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *chooserdialog = NULL;
     
            chooserdialog=GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
            gtk_widget_hide(chooserdialog);
    }
    Maintenant ce que j'aimerais faire c'est implémenter les callback de mes boutons : copier,coller,couper,supprimer.
    J'ai fouillé un peu partout sur internet, je pense avoir mal fouiller (non sans blague?lol) mais néanmoins je pose ma question. Quelqu'un aurait il une piste? Comment devrais-je procéder?

  18. #18
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    Je viens de voir que dans la liste des signaux de GTK, il y avait "copy_clipboard", "cut_clipboard", "paste-clipboard" ...
    Ca correspond bien à ce que je recherche? Et si oui, comment écrire dans les fonctions callback respectives qu'il s'agit d'une copie, d'un coller...etc etc

  19. #19
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2014
    Messages
    21
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 28
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2014
    Messages : 21
    Points : 1
    Points
    1
    Par défaut
    J'ai réussi à implémenter les raccourcis des bouttons que je recherchais grâce aux signaux prédéfinis découverts dans le gtk TextView et aux callbacks prédéfinis.
    J'ai donc le : Ctrl +C, Ctrl +V, Ctrl+X, Supp.
    Mais les boutons correcspondants à ces actions, je n'ai toujours pas pu les implémenter.

  20. #20
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 291
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 291
    Points : 4 941
    Points
    4 941
    Billets dans le blog
    5
    Par défaut
    Citation Envoyé par shumprevers Voir le message
    Bonjour, et bien j'ai réussi à afficher l'image. Quand on clique sur le bouton ajouter, on va jusqu'à retrouver le fichier dans le disque dur, puis on a la possibilité de cliquer sur valider ou sur cancel. Valider pour l'afficher et cancel pour annuler bien évidemment. J'ai Donc 3 callback. Est ce que c'est la meilleure façon de le faire? Des conseils?
    Voici les callbacks:
    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
     
    void callback_add(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            gint res;
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *add = NULL;
     
            add=  GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
            res = gtk_dialog_run (GTK_DIALOG (add));
    }
     
    void callback_validate(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *chooserdialog = NULL;
            chooserdialog=GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
     
            char *filename;
            GtkFileChooser *chooser = GTK_FILE_CHOOSER(chooserdialog);
            filename = gtk_file_chooser_get_filename(chooser);
     
            //affichage de l'image
            GtkImage *image = GTK_IMAGE(gtk_builder_get_object(data->builder,"Image"));
            gtk_image_set_from_file (image,filename);
     
            gtk_widget_hide(chooserdialog);
    }
     
    void callback_cancel(GtkMenuItem *menuitem, gpointer user_data)
    {
            if (menuitem != NULL)
            {
            }
            SGlobalData *data = (SGlobalData*) user_data;
            GtkWidget *chooserdialog = NULL;
     
            chooserdialog=GTK_WIDGET (gtk_builder_get_object (data->builder, "FileChooserWindow"));
            gtk_widget_hide(chooserdialog);
    }
    La meilleure façon je ne sais pas mais celle-ci est déjà pas mal. Tu as donc affecté le signal "clicked" de chaque bouton à un callback différent. C'est propre. Il est aussi possible de gérer toutes les possibilités dans une seule fonction (la fonction add(); en l'occurence). Mais c'est plus une histoire de goût. J'aime assez ta façon de faire car tu gardes la même méthode de gestion pour toutes tes fenêtres générées avec Glade.

Discussions similaires

  1. Erreur could not find signal handler
    Par moncef363 dans le forum GTK+
    Réponses: 4
    Dernier message: 06/06/2013, 15h08
  2. Réponses: 2
    Dernier message: 17/06/2010, 09h54
  3. Réponses: 2
    Dernier message: 12/04/2010, 18h47
  4. Gtk-WARNING **: Could not find signal handler
    Par yostane dans le forum GTK+ avec C & C++
    Réponses: 2
    Dernier message: 24/11/2008, 15h07

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