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 :

Problème entre win32 et Ubuntu


Sujet :

GTK+ avec C & C++

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 6
    Points : 5
    Points
    5
    Par défaut Problème entre win32 et Ubuntu
    Salut !

    Voilà je crois que j'ai trouvé un petit bug de GTK+... En fait mon code marche très bien sous Ubuntu, mais sous Windows ça ne marche pas du tout

    Quelques explications :
    Je programme une application (client IRC) et cela necessite des threads. Pour l'instant rien de spécial J'ai donc codé des classes pour gérer les sockets, thread et mutex pour les 2 systemes d'exploitation. J'ai testé en mode console, pas de soucis. Je me suis donc lancé sous GTK (que je connaissais pas du tout avant étant assez pro Visual) pour garder la portabilité !

    Mon pronlème :
    La création dynamique d'onglets. Sous linux pas de soucis, il est même tellement rapide que ça découaffe ! Mais sous windows c'est une autre histoire... CA BLOQUE CARREMENT !

    J'utilise pourtant ce qui est décrit sous la doc de GTK pour éviter ce soucis mais cela ne change rien...

    Exemple de programme :
    compiler avec g++ sous linux et visual 2003 sous windows :

    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
    /*
     * Compile with:
     *
     * @g++ -Wall -o gtk-thread main.cpp `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`
     *
     *
     */
     
    #ifndef __linux__
    	#pragma comment(lib, "gtk-win32-2.0.lib")
    	#pragma comment(lib, "gdk-win32-2.0.lib")
    	#pragma comment(lib, "glib-2.0.lib")
    	#pragma comment(lib, "gobject-2.0.lib")
    	#pragma comment(lib, "gthread-2.0.lib")
    #endif
     
    #include <iostream>
    #ifndef __linux__
    	#include <windows.h>
    #endif
    #include <gtk/gtk.h>
    #include <glib/gprintf.h>
     
     
    typedef struct
    {
      GtkWidget *noteBook;
    } WidgetNoteBook;
     
     
    void addPage(GtkWidget * notebook, const char *name);
     
    void destroy(GtkWidget *widget, gpointer data)
    {
      gtk_main_quit();
    }
     
    void *argument_thread(void *args)
    {
      WidgetNoteBook *data = (WidgetNoteBook *)args;
     
      while(1)
        {
          /* sleep a while */
    	#ifndef __linux__
          Sleep(g_random_int_range (1000, 4000));
    	#else
    	  sleep(g_random_int_range (1, 4));
    	#endif
     
    	 addPage((GtkWidget *)data->noteBook, "thread");
     
        }
     
      return NULL;
    }
     
    /* get GTK thread lock */
    inline void enter() {  gdk_threads_enter(); };
    /* release GTK thread lock */
    inline void leave() {  gdk_flush(); gdk_threads_leave(); };
     
    void addPage(GtkWidget * notebook, const char *name)
    {
    	if(notebook)
    	{
     
    		/*static int i=0;
    		char titre[100], contenu[100];
     
    		sprintf(titre, "Titre %d", i);
    		sprintf(contenu, "Page %d", i);
     
    		GtkWidget *pTabLabel, *pLabel;
    		pTabLabel = gtk_label_new(titre);
    		gtk_widget_show (pTabLabel);
    		pLabel = gtk_label_new(contenu);
    		gtk_widget_show(pLabel);
     
    		enter();
    		gtk_notebook_append_page(GTK_NOTEBOOK (notebook), pLabel, pTabLabel);
    		leave();
    		gtk_widget_show(notebook);
    		i++;*/
     
    		GtkWidget *pHBox;
    		pHBox = gtk_hbox_new(FALSE, 5);
    		gtk_widget_show(pHBox);
     
    		// Textview
    		GtkWidget *pScrolled;
    		GtkWidget *pTextView;
     
    		pScrolled = gtk_scrolled_window_new(NULL, NULL);
    		gtk_widget_show(pScrolled);
     
    		pTextView=gtk_text_view_new();
    		gtk_widget_show(pTextView);
    		gtk_text_view_set_editable(GTK_TEXT_VIEW(pTextView), FALSE);
    		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (pScrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    		gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(pScrolled), GTK_SHADOW_IN);
    		enter();
    		gtk_container_add(GTK_CONTAINER(pScrolled), pTextView);
    		leave();
     
    		// Liste
    		GtkWidget *pListView;
    		GtkWidget *pScrollbar;
    		GtkListStore *pListStore;
    		GtkTreeViewColumn *pColumn;
    		GtkCellRenderer *pCellRenderer;
     
    		pListStore = gtk_list_store_new(1, G_TYPE_STRING);
    		pListView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(pListStore));
    		gtk_widget_show(pListView);
    		gtk_widget_set_size_request(pListView, 120, -1);
     
    		pCellRenderer = gtk_cell_renderer_text_new();
    		pColumn = gtk_tree_view_column_new_with_attributes("Utilisateurs", pCellRenderer, "text", 0, NULL);
    		enter();
    		gtk_tree_view_append_column(GTK_TREE_VIEW(pListView), pColumn);
    		leave();
     
    		pScrollbar = gtk_scrolled_window_new(NULL, NULL);
    		gtk_widget_show(pScrollbar);
    		gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(pScrollbar), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
    		gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(pScrollbar), GTK_SHADOW_IN);
    		enter();
    		gtk_container_add(GTK_CONTAINER(pScrollbar), pListView);
    		leave();
     
    		// Onglet
    		GtkWidget *pHBoxOnglet;
    		GtkWidget *pButtonOnglet;
    		GtkWidget *pTabLabel;
     
    		pHBoxOnglet = gtk_hbox_new(FALSE, 0);
    		gtk_widget_show(pHBoxOnglet);
     
    		char *text=g_convert(name, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
    		pTabLabel = gtk_label_new(text);
    		gtk_widget_show(pTabLabel);
    		g_free(text);
     
    		pButtonOnglet = gtk_button_new_with_label(" x ");
    		gtk_widget_show(pButtonOnglet);
    		gtk_button_set_relief (GTK_BUTTON (pButtonOnglet), GTK_RELIEF_NONE);
     
    		gtk_box_pack_start(GTK_BOX (pHBoxOnglet), pTabLabel, FALSE, FALSE, 0);
    		gtk_box_pack_start(GTK_BOX (pHBoxOnglet), pButtonOnglet, FALSE, FALSE, 0);
    		gtk_box_pack_start(GTK_BOX (pHBox), pScrolled, TRUE, TRUE, 0);
    		gtk_box_pack_start(GTK_BOX(pHBox), pScrollbar, FALSE, FALSE, 0);
     
    		enter();
    		gtk_notebook_append_page(GTK_NOTEBOOK(notebook), pHBox, pHBoxOnglet);
    		leave();
    	}
    }
     
    int main(int argc, char *argv[])
    {
      GtkWidget *window;
      GError *error = NULL;
      WidgetNoteBook yes_args;
     
      /* init threads */
      g_thread_init(NULL);
      gdk_threads_init();
     
      /* init gtk */
      gtk_init(&argc, &argv);
     
      /* create a window */
      window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_window_set_default_size(GTK_WINDOW(window), 320, 200);
      g_signal_connect(window, "destroy", G_CALLBACK(destroy), NULL);
      gtk_container_set_border_width(GTK_CONTAINER (window), 0);
     
      /* create a label */
      GtkWidget *pNotebook;
      pNotebook = gtk_notebook_new();
      gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pNotebook), GTK_POS_TOP);
      gtk_notebook_set_scrollable(GTK_NOTEBOOK(pNotebook), TRUE);
      gtk_container_add(GTK_CONTAINER(window), pNotebook);
     
      addPage(pNotebook, "Main");
     
      /* show everything */
      gtk_widget_show(pNotebook);
      gtk_widget_show(window);
     
      /* create the threads */
      yes_args.noteBook = pNotebook;
      if (!g_thread_create(argument_thread, &yes_args, FALSE, &error))
        {
          g_printerr ("Failed to create YES thread: %s\n", error->message);
          return 1;
        }
     
      //gtk_widget_show_all(window);
     
      /* enter the GTK main loop */
      gdk_threads_enter();
      gtk_main();
      gdk_threads_leave();
     
      return 0;
    }
    si quelque'un a la force de regarder j'en serais très heureux

  2. #2
    Membre éprouvé
    Avatar de Celelibi
    Profil pro
    Inscrit en
    Janvier 2004
    Messages
    1 087
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2004
    Messages : 1 087
    Points : 1 122
    Points
    1 122
    Par défaut
    À priori y'a rien de spécial dans ton code (d'ailleurs ça marche sous Linux).
    Tu devrais peut-être essayer de débugger ton programme pour voir où ça bug.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 6
    Points : 5
    Points
    5
    Par défaut
    Déjà merci d'avoir répondu

    sinon j'ai bien tenté de debugger... mais bon ça plante sévère je pense qu'il y a une mauvaise gestion de la section critique GTK sous windobe ! Je suis allé voir sur la liste des bugs de GTK et c'est en anglais, mais je crois qu'elle est signalé Faut donc que j'attende qu'ils réparent lol... pour l'instant ça sera un prog linux ! et pi c'est tout

  4. #4
    Rédacteur

    Avatar de gege2061
    Femme Profil pro
    Administrateur de base de données
    Inscrit en
    Juin 2004
    Messages
    5 840
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Administrateur de base de données

    Informations forums :
    Inscription : Juin 2004
    Messages : 5 840
    Points : 11 625
    Points
    11 625

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 6
    Points : 5
    Points
    5
    Par défaut
    J'avais déjà testé cette aide... malheureusement cela ne donne rien... toujours un beau blocage, mais merci quand même

Discussions similaires

  1. Réponses: 2
    Dernier message: 04/02/2010, 21h52
  2. Probléme entre programme maison et ubuntu.
    Par Ubiquité dans le forum C
    Réponses: 1
    Dernier message: 22/12/2007, 17h28
  3. Problème entre IB 6.0 et Access 2000
    Par Polux63 dans le forum InterBase
    Réponses: 3
    Dernier message: 19/04/2004, 10h34
  4. Problème entre Dev-c++ et Borland c++ compiler 5.5
    Par Argonz dans le forum Dev-C++
    Réponses: 6
    Dernier message: 21/10/2003, 16h21
  5. [ODBC] Problème entre access et ODBC
    Par StephCal dans le forum Access
    Réponses: 4
    Dernier message: 09/07/2003, 16h47

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