GTK+ Forums

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

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: GTK Notbook Change Pages
PostPosted: Fri Sep 21, 2012 6:28 pm 
Offline
Familiar Face

Joined: Sat Mar 03, 2012 2:45 am
Posts: 18
Hello All,

I am trying to write a function to change tabs on a click of a button. My Code is Below. It errors out saying "Gtk-CRITICAL **: gtk_notebook_set_current_page: assertion `GTK_IS_NOTEBOOK (notebook)' failed" I am showing the widget. I know that is in the gnome help.

Any Ideas?

Code:
void btn_login_clicked_cb (GtkButton *btn_login, GtkNotebook *notebook, gpointer user_data)
{
   GtkWidget *login = GTK_WIDGET(btn_login);
   gtk_button_set_label (login, "Please Wait..."); // THIS WORKS :)

   GtkWidget *nb = GTK_WIDGET(notebook);
   gtk_widget_show_all(nb);
   gtk_notebook_set_current_page (nb, 1); // THIS DOES NOT
}


Thank You


Top
 Profile  
 
 Post subject: Re: GTK Notbook Change Pages
PostPosted: Fri Sep 21, 2012 10:37 pm 
Offline
Never Seen the Sunlight

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

You haven't read the docs about signal connections properly. Prototype of each signal handler is documented in API docs. Signal for GtkButton::clicked (I guess that is the signal you're connecting to) is
Code:
void callback (GtkButton *button, gpointer data)

Your callback has 3 arguments, which means that your local variables most probably contain garbage. Read docs about signal connection and then search this forum for methods of passing data around the various parts of your app and you should be able to fix this.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: GTK Notbook Change Pages
PostPosted: Fri Sep 21, 2012 11:44 pm 
Offline
Familiar Face

Joined: Sat Mar 03, 2012 2:45 am
Posts: 18
I have looked at the Signal Connection and having multiple arguments in GTK while on google and gtkforurms.com - I have found http://stackoverflow.com/questions/6684466/c-passing-multiple-arguments-to-a-callback-function-in-gtk and http://ubuntuforums.org/showthread.php?t=701485 but still not working. I created a struct with GtkWidget *btn_login, GtkWidget *notebook, and still has an error. I can't see what I am doing wrong in it.

Code:
struct widgets_login
{
    GtkWidget *btn_login;
    GtkWidget *notebook;
};


void btn_login_clicked_cb (GtkWidget *btn_login, gpointer data)
{
   struct widgets_login * w ;
   w = ( struct widgets_login *) data ;

   GtkWidget *login = GTK_WIDGET(btn_login);
   gtk_widget_set_sensitive (login, FALSE);
   gtk_button_set_label (login, "Please Wait...");
   
   gtk_notebook_set_current_page(GTK_NOTEBOOK(w->notebook), 1);
}


Top
 Profile  
 
 Post subject: Re: GTK Notbook Change Pages
PostPosted: Sat Sep 22, 2012 1:27 pm 
Offline
Never Seen the Sunlight

Joined: Thu Mar 24, 2011 2:10 pm
Posts: 328
Location: Sydney, Australia
Why are you putting the button in a structure. It is already passed as being the one that the signal activates on. In this case you only need to pass the notebook and so don't need a structure; thus can pass it in the gpointer as is. E.g.:
Code:
void btn_login_clicked_cb (GtkButton *btn_login, gpointer data)
{
   gtk_widget_set_sensitive (GTK_WIDGET(btn_login), FALSE);
   gtk_button_set_label (login, "Please Wait...");
   gtk_notebook_set_current_page(GTK_NOTEBOOK(data), 1);
}

int main(int argc, char *argv[])
{
   ...
   g_signal_connect(G_OBJECT(btn_login), "clicked", G_CALLBACK(btn_login_clicked_cb), (gpointer) notebook);
   ...


The other thing is: Yes you are allowed to declare a global variable. And for something like a notebook that is routinely altered by various functions, it makes sense to do so. Structured programming may say otherwise but to that I say goto


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group