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 Oct 24, 2014 11:53 pm

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: entry text
PostPosted: Sun Mar 01, 2009 5:50 am 
Offline
GTK+ Geek

Joined: Wed Dec 31, 2008 12:44 am
Posts: 73
Location: Fort Worth TX
Whats a easy way to get the text from a entry?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 9:29 am 
Offline
GTK+ Geek

Joined: Thu Dec 20, 2007 5:24 pm
Posts: 56
Location: Turkey
gtk_entry_get_text () ( http://library.gnome.org/devel/gtk/stab ... y-get-text )

Code:
GtkWidget my_entry;
gchar *my_string;

...

my_string = gtk_entry_get_text (GTK_ENTRY (my_entry));

...


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 7:20 pm 
Offline
GTK+ Geek

Joined: Wed Dec 31, 2008 12:44 am
Posts: 73
Location: Fort Worth TX
I tried that and i get nothing here's the code:

Code:
GtkWidget *entry;
gchar *entrytext;

entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
entrytext = gtk_entry_get_text(GTK_ENTRY(entry));
g_printf("The text in the entry box was %s",entrytext);


when i type in the entry and click ok it says "The text in the entry box was" and thats it?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 9:33 pm 
Offline
Never Seen the Sunlight

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

Below you'll find really simple application that demonstrates retrieval of text from GtkEntry. Hope you'll find it useful.

Code:
#include <gtk/gtk.h>

static void
cb_clicked( GtkButton *button,
         GtkEntry  *entry )
{
   g_print( "The text in entry box was %s\n", gtk_entry_get_text( entry ) );
}

int
main( int    argc,
     char **argv )
{
   GtkWidget *window;
   GtkWidget *hbox;
   GtkWidget *entry;
   GtkWidget *button;

   gtk_init( &argc, &argv );

   window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
   g_signal_connect( G_OBJECT( window ), "destroy",
                 G_CALLBACK( gtk_main_quit ), NULL );

   hbox = gtk_hbox_new( FALSE, 6 );
   gtk_container_add( GTK_CONTAINER( window ), hbox );

   entry = gtk_entry_new();
   gtk_box_pack_start( GTK_BOX( hbox ), entry, TRUE, TRUE, 0 );

   button = gtk_button_new_with_label( "Print" );
   g_signal_connect( G_OBJECT( button ), "clicked",
                 G_CALLBACK( cb_clicked ), GTK_ENTRY( entry ) );
   gtk_box_pack_start( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );

   gtk_widget_show_all( window );

   gtk_main();

   return( 0 );
}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 11:33 pm 
Offline
GTK+ Geek

Joined: Wed Dec 31, 2008 12:44 am
Posts: 73
Location: Fort Worth TX
Well thats a great example but i need to get the text from a entry on a dialog. I dont know how to do a callback on a dialog button?


Last edited by thinice16 on Sun Mar 01, 2009 11:36 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 11:35 pm 
Offline
Never Seen the Sunlight

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

The main "catch" of obtaining text from dialog is passing the right widget (or structure) as a callback's user data.

If you provide more specific needs, I may be able to help you a bit more.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 11:38 pm 
Offline
GTK+ Geek

Joined: Wed Dec 31, 2008 12:44 am
Posts: 73
Location: Fort Worth TX
Im trying to get the text from the entry to put as the window title and to create the file. so i just dont know how to do a callback on a dialog button. thanks for the quick reply.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 11:46 pm 
Offline
GTK+ Geek

Joined: Wed Dec 31, 2008 12:44 am
Posts: 73
Location: Fort Worth TX
I did it!!!!! Thanks tadeboro here's the code:


Code:
static void get_filename( GtkButton *button, GtkEntry  *dbentry )
{
    g_print( "The text in entry box was %s\n", gtk_entry_get_text( dbentry ) );
}

if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  {
   get_filename(GTK_RESPONSE_ACCEPT,GTK_ENTRY(dbentry));
  }


Thanks for all the help.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot], 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