GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Sep 18, 2014 11:46 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: get data from combo box
PostPosted: Tue Aug 21, 2012 1:54 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Dear friends,
My code looks like:
Code:
GtkWidget *entryAuth;
GtkWidget *entryEditor;
GtkWidget *entryTitle;
GtkWidget *entry1;
GtkWidget *combo;


typedef struct {
GtkWidget *combo, *entry1, *entryAuth, *entryEditor,*entryTitle;
} Entries;


static void
activate_func (GtkWidget *widget, gpointer data)
{
  Entries *e = (Entries*) data;
  const gchar  *strcombo, *strkey, *strAuth, *strEditor, *strTitle;
  strcombo = gtk_combo_box_get_active_text(GTK_COMBO_BOX(e->combo));
  strkey = gtk_entry_get_text(GTK_ENTRY(e->entry1));
  strAuth = gtk_entry_get_text(GTK_ENTRY(e->entryAuth));
  strEditor = gtk_entry_get_text(GTK_ENTRY(e->entryEditor));
  strTitle = gtk_entry_get_text(GTK_ENTRY(e->entryTitle));

  g_print (strcombo);
  g_print (strkey);
  g_print (strAuth);
  g_print (strEditor);
  g_print (strTitle);
}


int main(int argc,
        char *argv[]) {
    Entries *e = g_slice_new (Entries);
/*****/
    e->combo = gtk_combo_box_text_new();
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(e->combo), "Book");
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(e->combo), "Article");
    gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(e->combo), "Booklet");
   e-> entryAuth = gtk_entry_new();
   gtk_entry_set_placeholder_text (GTK_ENTRY (e->entryAuth), "Hostname");

  e->  entryEditor = gtk_entry_new();
    gtk_entry_set_placeholder_text(GTK_ENTRY(e->entryEditor), "Editor");

  e->  entryTitle = gtk_entry_new();
    gtk_entry_set_placeholder_text(GTK_ENTRY(e->entryTitle), "Title");

    label = gtk_label_new("Authors/Title");
    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), frame, label);

    gtk_grid_attach (GTK_GRID (page1), e->  entryAuth, 0, 0, 1, 1);
    gtk_grid_attach (GTK_GRID (page1), e->entryEditor, 0, 4, 1, 1);
    gtk_grid_attach (GTK_GRID (page1), e-> entryTitle, 0, 8, 1, 1);

    button = gtk_button_new_with_label("CREATE");
    g_signal_connect (button, "clicked", G_CALLBACK (activate_func), e);

    gtk_grid_attach (GTK_GRID (grid), e->combo, 0, 1, 1, 1);
    gtk_grid_attach (GTK_GRID (grid), e->entry1, 1, 1, 1, 1);
     gtk_widget_show_all (window);
     gtk_main ();

  return 0;
}


when I am trying to compile it, I am getting error:
$ gcc try_entry.c -o centry `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`
try_entry.c: In function ‘activate_func’:
try_entry.c:63:12: warning: assignment makes pointer from integer without a cast [enabled by default]
/tmp/ccDkMhTQ.o: In function `activate_func':
try_entry.c:(.text+0x3b): undefined reference to `gtk_combo_box_get_active_text'
collect2: error: ld returned 1 exit status

but if I put combo entry out of the activate_func and the structure, its running fine.
So, my question in how should I include a combo along with entry in a structure and extract the data?

Please reply.


Top
 Profile  
 
 Post subject: Re: get data from combo box
PostPosted: Tue Aug 21, 2012 4:29 pm 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hi.

Did you simply misspell the function? I think the function you need is called gtk_combo_box_text_get_active_text () and not gtk_combo_box_get_active_text ().

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: get data from combo box
PostPosted: Tue Aug 21, 2012 7:23 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Thanks.
Its working.


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: Yahoo [Bot] and 2 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