LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-30-2011, 12:42 AM   #1
nitish0863
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
unable to get result from LINUX GTK C program please help


hi i am using following code to print the data which entered in the entry box



#include<glib.h>
#include<gtk/gtk.h>
int i=0;
const gchar *buffer;
GtkWidget *entry;

gint delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
{
gtk_main_quit ();
return FALSE;
}
void entry_toggle_editable( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_editable_set_editable (GTK_EDITABLE (entry),
GTK_TOGGLE_BUTTON (checkbutton)-> active);
}

void clear( GtkWidget *widget, gpointer data )
{
//g_print ("%s ", (gchar *) data);
//g_print ("%s\n", (gchar *) data);
gtk_entry_set_text (GTK_ENTRY (entry), "");
//gtk_text_set_text (" ");
}
/*void submit( GtkWidget *widget, gpointer data )
{
buffer =gtk_entry_get_buffer(GtkEntry *entry);
printf("%s",buffer);
}*/

void submit( GtkWidget *widget,
GtkWidget *entry )
{

const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
printf("Entry contents: %s\n", entry_text);

}



int main( int argc, char *argv[] )
{
GtkWidget *window;
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *button;
GtkWidget *separator;
GtkWidget *text;
GtkWidget *table;
GSList *group;
GtkWidget *view;
GSList *check;
//GtkWidget *entry;
GtkTextBuffer *buffer;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Caluclator");
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (delete_event), NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), 20);



box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_widget_show (box1);


box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 100);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
gtk_widget_show (box2);


table = gtk_table_new (5, 5,TRUE);
//gtk_table_set_row_spacing (GTK_TABLE (table), 0, 5);
//gtk_table_set_col_spacing (GTK_TABLE (table), 0, 5);
gtk_box_pack_start (GTK_BOX (box2), table, TRUE, TRUE, 0);
gtk_widget_show (table);



entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 10);
// g_signal_connect (G_OBJECT (entry), "activate",
//G_CALLBACK (enter_callback),
//(gpointer) entry);
gtk_entry_set_text (GTK_ENTRY (entry), " ");
gtk_table_attach_defaults(GTK_TABLE (table), entry, 0, 4, 1, 4);
gtk_widget_show (entry);

button = gtk_button_new_with_label("clear");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (clear), (gpointer) " ");
gtk_table_attach_defaults (GTK_TABLE (table), button, 0,2, 4, 5);
gtk_widget_show (button);

button = gtk_button_new_with_label("Quit");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (delete_event), (gpointer) " ");
gtk_table_attach_defaults (GTK_TABLE (table), button, 2,4, 4, 5);
gtk_box_pack_start (GTK_BOX (box1), button, TRUE, TRUE, 0);
gtk_widget_show (button);


check = gtk_check_button_new_with_label ("Editable");
//gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
gtk_table_attach_defaults (GTK_TABLE (table), check, 0,1, 0, 1);
g_signal_connect (G_OBJECT (check), "toggled",
G_CALLBACK (entry_toggle_editable), (gpointer) entry);
//gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
gtk_widget_show (check);

button = gtk_button_new_with_label("submit");
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (submit), (gpointer) " ");
gtk_table_attach_defaults (GTK_TABLE (table), button, 0,3, 3, 4);
gtk_widget_show (button);

gtk_widget_show (window);
gtk_main ();
return 0;
}


?*******i am getting the following error while compiling*****



gtk/gtktable.h:119:9: note: expected ‘struct GtkWidget *’ but argument is of type ‘struct GSList *’
dir.c:114:1: warning: passing argument 1 of ‘gtk_widget_show’ from incompatible pointer type
/usr/include/gtk-2.0/gtk/gtkwidget.h:851:9: note: expected ‘struct GtkWidget *’ but argument is of type ‘struct GSList *’
nitish@nirab-WSG37455V-0564:~/myexamples/assaign$ ./dir

(dir:7389): Gtk-CRITICAL **: gtk_box_pack: assertion `child->parent == NULL' failed
Segmentation fault

/*********and getting following error while running.*********/

gtk_box_pack: assertion `child->parent == NULL' failed
Segmentation fault



GUI:
 
Old 12-30-2011, 05:52 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
The Gtk CRITICAL error is coming from this line:

Code:
 gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
Commenting it out gets rid of that error.

The seg fault is coming from your call to GTK_ENTRY(entry) in the submit() function. I would double check what you're doing with submit, and the entry object.

Also, do change your GSList *check to a GtkWidget *check, as per the warning.
 
Old 01-02-2012, 03:16 AM   #3
nitish0863
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jhwilliams View Post
The Gtk CRITICAL error is coming from this line:

Code:
 gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
Commenting it out gets rid of that error.

The seg fault is coming from your call to GTK_ENTRY(entry) in the submit() function. I would double check what you're doing with submit, and the entry object.

Also, do change your GSList *check to a GtkWidget *check, as per the warning.
thanks williams :


what i want is take input from text box and print the out put in text box
could u please give me code for that program
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running external program using C and read the result output Kunsheng Programming 15 11-17-2009 12:08 PM
Question, QT, GTK ... is there any more language to program a GUI in linux??? webquinty Linux - Newbie 4 11-07-2008 01:04 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration