GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Sep 19, 2014 7:52 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Alternative to gtk_tree_path_to_string?
PostPosted: Thu Jun 26, 2008 7:56 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
I'm using this function to know the selected index of my listview:
Code:
void on_changed(GtkWidget *widget, gpointer label)  {
   GtkTreeIter iter;
     GtkTreeModel *model;
   gchar *value;    
   if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(widget), &model, &iter)) {
      GtkTreePath *path;
      gchar *zpath;
       gtk_tree_model_get(model, &iter, 0, &value,  -1);
       path = gtk_tree_model_get_path(model, &iter);
       zpath = gtk_tree_path_to_string(path);
       g_print("Index: %s. Value: %s\n", zpath, value);
       gtk_tree_path_free(path);
       g_free(zpath);
       g_free(value);
    }
}

Since gtk_tree_path_to_string returns the index in a string, ins't there like a function to automatically returns the index in gint instead of gchar?
Thanks for your time.

/edit:
forgot!
If there's not possible, is there an atoi wrapper in gtk to convert the string into integer? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 2:12 am 
Offline
Never Seen the Sunlight

Joined: Thu Jun 14, 2007 11:02 pm
Posts: 923
Location: Falun, WI USA
the string that gtk_tree_path_to_string returns can't be converted into a number unless you're using a GtkListStore,
that's because it uses the colon ':' to separate paths, ex:
0:1:4:3
it would work on a GtkListStore though, because they can't have more than one depth, so their paths would look like:
2 or 4

as for the atoi wrapper, I don't believe that there is one, so I guess you'll just have to use atoi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 27, 2008 2:19 am 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
As always dreblen, thanks for your time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group