GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 01, 2014 4:05 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Why is my simple code not working ?
PostPosted: Wed Apr 09, 2014 7:01 pm 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Error :: Gtk-CRITICAL **: gtk_window_set_title: assertion 'GTK_IS_WINDOW (window)' failed


Code:
#include <gtk/gtk.h>


struct init{
   GtkWidget *button;
   GtkWidget * window;
   int status;
};


void titlebar(GtkWidget *widget,struct init any){
  if(any.status){

  gtk_window_set_title(GTK_WINDOW(any.window),"ahahaha");
  any.status = 0;

   }

  else{

    gtk_window_set_title(GTK_WINDOW(any.window),"noooooo");
    any.status = 1;
  }
}


int main(int argc,char * argv[]){

    struct init main;

   gtk_init(&argc,&argv);

   main.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size(GTK_WINDOW(main.window), 230,150);
    gtk_window_set_title(GTK_WINDOW(main.window), "Crazy shit");

   main.button = gtk_button_new_with_label("click me to change title");
   main.status = 1;

   gtk_container_add(GTK_CONTAINER(main.window),main.button);

   g_signal_connect(main.window, "destroy",G_CALLBACK(gtk_main_quit), G_OBJECT(main.window));
   g_signal_connect(G_OBJECT(main.button),"clicked",G_CALLBACK(titlebar),main.window);


    gtk_widget_show_all(main.window);

   gtk_main();

}


Top
 Profile  
 
 Post subject: Re: Why is my simple code not working ?
PostPosted: Wed Apr 09, 2014 7:34 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 750
Location: UK
The signal call-back function titlebar() is expecting as the second argument a structure.
Code:
void titlebar(GtkWidget *widget,struct init any)

When you have connected the signal using
Code:
g_signal_connect(G_OBJECT(main.button),"clicked",G_CALLBACK(titlebar),main.window);
you are passing as the second argument a pointer to the GtkWindow. These are not the same type. This is why you have the run-time error

You will need to re-write the function titlebar() so that the second argument is a pointer and not a structure and to make sure that the types used by the function titlebar() and that passed to the function to connect the signal are the same.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Why is my simple code not working ?
PostPosted: Thu Apr 10, 2014 5:06 am 
Offline
Familiar Face

Joined: Fri Jan 10, 2014 2:29 pm
Posts: 21
Thanks ,it worked


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: Google [Bot] 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