Thread: GTK+ Programmng Help: Last Resort!

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    25

    GTK+ Programmng Help: Last Resort!

    Hi everyone,

    I have a combo box in which there are a few words. I am trying to build a menu option that will generate a LaTeX file with those words, that can then be compiled to produce PDF output. For that, I need to first obtain the list of words that already in the combo box.

    I checked the DevHelp documentation thoroughly; in particular, I looked at the sample programmes in the section on GtkTreeModel. The sample given there is almost exactly what I am doing here. (The only difference is that in the sample programme a new tree model is built explicitly, whereas in my code below, I am obtaining the tree model from the combo box known as WordListComboBox.) Note: The code below shows only the relevant portion.

    I am at a total loss as to why the following code will not work:

    Code:
    void on_generate_tex_activate (GtkMenuItem     *menuitem, gpointer user_data)
    {
    
      GtkTreeModel *TreeModel;
      GtkTreeIter Iter;
      gboolean Valid;
    
      TreeModel = gtk_combo_box_get_model(GTK_COMBO_BOX(lookup_widget(GTK_WIDGET(menuitem), "WordListComboBox")));
    
      Valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(TreeModel), &Iter);
    
      while(Valid) {
    
        gchar Word[65];
        gint i;
        for(i = 0; i < 65; i++) {
          Word[i] = '\0';
        } /* End for(i) */
    
        gtk_tree_model_get(GTK_TREE_MODEL(TreeModel), &Iter, 0, &Word[0], -1);
        g_print("%s\n", &Word[0]);
    
        Valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(TreeModel), &Iter);
    
      } /* End while() */
    
    }
    When I run the programme and activate the menu option, instead of seeing the words in the combo box echoed in the terminal, I get strange characters. However, the number of lines of strange characters always matches the number of words in currently in the combo box.

    Can someone please tell me what I am doing incorrectly? Instead of output like:

    word_1
    word_2
    word_3

    why do I see:

    ..P
    *Q>
    >V,

    Thanks in advance for your help.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Possibly because the gtk_tree_model_get requires a pointer of type gchar for the returned string as indicated in the GTK documentation.

    Code:
             gchar *Word;    
             gtk_tree_model_get(GTK_TREE_MODEL(TreeModel), &Iter, 0, &Word, -1);
             g_print("%s\n", Word);

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    25
    Quote Originally Posted by BobS0327
    Possibly because the gtk_tree_model_get requires a pointer of type gchar for the returned string as indicated in the GTK documentation.

    Code:
             gchar *Word;    
             gtk_tree_model_get(GTK_TREE_MODEL(TreeModel), &Iter, 0, &Word, -1);
             g_print("%s\n", Word);
    Thanks for responding, Bob. But if Word is a pointer to gchar, then &Word is of type gchar**. You should get an error if you try to compile the above lines.

    I believe I have the syntax right when I write:

    gtk_tree_model_get(GTK_TREE_MODEL(TreeModel), &Iter, 0, &Word[0], -1);

    because &Word[0] is indeed a pointer to gchar.

    *****

    I still have not figured out the problem. Any help would be greatly appreciated.

    *****

    Edit

    Never mind! Thank you very much, Bob! You are right!

    What a remarkable case of blindness on my part!
    Last edited by Reisswolf; 04-23-2006 at 11:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2008, 04:49 AM
  2. Help on GTK
    By kakashi in forum C++ Programming
    Replies: 1
    Last Post: 03-08-2006, 02:33 AM
  3. GTK troubles...again...
    By cornholio in forum Linux Programming
    Replies: 4
    Last Post: 01-16-2006, 01:37 AM
  4. GTK Help
    By Cronkilla in forum C Programming
    Replies: 2
    Last Post: 08-24-2004, 06:23 PM
  5. QT or GTK
    By mart_man00 in forum Linux Programming
    Replies: 4
    Last Post: 03-24-2003, 10:42 PM