GTK+ Programmng Help: Last Resort!

This is a discussion on GTK+ Programmng Help: Last Resort! within the Linux Programming forums, part of the Platform Specific Boards category; Hi everyone, I have a combo box in which there are a few words. I am trying to build a ...

  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,059
    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-24-2006 at 12:25 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2008, 05: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, 07:23 PM
  5. QT or GTK
    By mart_man00 in forum Linux Programming
    Replies: 4
    Last Post: 03-24-2003, 10:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21