GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Jul 29, 2014 6:41 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: What's wrong with my code?
PostPosted: Wed Apr 11, 2012 3:05 pm 
Offline

Joined: Wed Apr 11, 2012 2:59 pm
Posts: 4
So I have to make a simple program in C using GTK for my class. So pretty much a window with 2 buttons, and an exit button below them. Then a popup asking if the user is sure if he wants to exit.

My problem is when I'm compiling, I don't understand why I am getting these errors or how to fix them. Please help me :).
For compiling I use: cc main.c -o win `pkg-config --clfags --libs gtk+-2.0`

(win:2654): Gtk-CRITICAL **: IA__gtk_container_add: assertion `GTK_IS_WIDGET (widget)' failed

(win:2654): Gtk-CRITICAL **: IA__gtk_table_attach: assertion `GTK_IS_TABLE (table)' failed

(win:2654): Gtk-CRITICAL **: IA__gtk_table_attach: assertion `GTK_IS_TABLE (table)' failed

(win:2654): Gtk-CRITICAL **: IA__gtk_widget_show: assertion `GTK_IS_WIDGET (widget)' failed

Code
Code:

#include <gtk/gtk.h>

void day(GtkWidget* w, gpointer data)
{
   g_print("The sun comes out during the day.\n");
}

void night(GtkWidget*w, gpointer data)
{
   g_print("The moon comes out during the night.\n");
}

gint delete_event(GtkWidget* w, GdkEvent* e, gpointer data)
{
   g_print("Please use exit button\n");
   return TRUE;
}

void destroy(GtkWidget* w, gpointer data)
{
   gtk_main_quit();
}

int main(int argc, char** argv)
{
   GtkWidget* win;
   GtkWidget* button;
   GtkWidget* table;

   //////////Window//////////
   gtk_init(&argc, &argv);
   win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   g_signal_connect(G_OBJECT(win), "delete_event", G_CALLBACK(delete_event), NULL);
   g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(destroy), NULL);
   gtk_container_set_border_width(GTK_CONTAINER(win), 20);
   //////////////////////////

   /////////Table//////////////
   gtk_table_new(3,3,TRUE);   
   gtk_container_add(GTK_CONTAINER(win), table);
   ////////////////////////////

   /////////////////Day Button//////////////////////
   button = gtk_button_new_with_label("Day");
   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(day), NULL);
   gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 0, 1);
   gtk_widget_show(button);
   /////////////////////////////////////////////////


   //////////////////////Night Button///////////////////
   button = gtk_button_new_with_label("Night");
   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(night), NULL);
   //gtk_table_attach_defaults(GTK_TABLE(table), button, 1, 2, 0, 1);
   gtk_table_attach_defaults(GTK_TABLE(table), button, 2, 3, 0, 1);
   gtk_widget_show(button);
   /////////////////////////////////////////////////////

   /////////////////Exit Button////////////////////////
   ////////////////////////////////////////////////////

   //////////////////////Table/////////////////////
   gtk_widget_show(table);
   ////////////////////////////////////////////////

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


Top
 Profile  
 
 Post subject: Re: What's wrong with my code?
PostPosted: Wed Apr 11, 2012 7:34 pm 
Offline
Familiar Face

Joined: Thu Dec 15, 2011 6:23 pm
Posts: 36
Location: Hrvatska
hi and welcome,
you miss this one:
Code:
table = gtk_table_new(3,3,TRUE);

one more error, this one is so cool, maybe you wanna leave it - there is no EXIT button :-)
cheers !
good luck with your class ...


Top
 Profile  
 
 Post subject: Re: What's wrong with my code?
PostPosted: Wed Apr 11, 2012 9:55 pm 
Offline

Joined: Wed Apr 11, 2012 2:59 pm
Posts: 4
Wow thank you, I can't believe i forgot to do that. It was driving me crazy.

I know about the exit problem :P, there is button I am adding to make it eixt.


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 4 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