Link to home
Start Free TrialLog in
Avatar of webservjava
webservjava

asked on

Pressing "x" button in a GTK window.

When I press the corner "X" button in a GTK+ window (I usse libglade)  the window closes and I cannot reopen it. GTK complains that  "file gtkwidget.c: line 1427 (gtk_widget_show): assertion `widget != NULL' failed." It appears that clicking on the "x" makes the pointer "NULL".
Avatar of akshayxx
akshayxx
Flag of United States of America image

it is because , u r not destroying the window on presing 'x' button .. most likely u are calling gtk_widget_hide on it ..
tell me the callback that u have registered on that 'x' button .. did u use glade for developing ?..
Avatar of sunnycoder
akshay is right

>>file gtkwidget.c: line 1427 (gtk_widget_show): assertion `widget != NULL' failed."

appears that you closed the window but did not free up the space i.e. did not "destroy" it ....

the pointer would still be holding the address of previous widgets....

while closing the window, free the space you have allocated and set the pointers to NULL
if u r using glad or not .. it will be simple .. just make sure to set gtk_widget_destroy as the call back for the 'x' button of window .. as i suppose u dont want to use it anymore...
OR keep a global handle of the window .. and when u want to show it again .. check it the handle is not NULL then call only gtk_widget_show . instead of creating the same window again .. this helps in cases like u have a FILE selection dialog .. and u expect to use it many times.. then every time u close it .. just hide it .. and create it at the start of the application ..and gtk_widget_show it everytime u want to show it..
Avatar of webservjava
webservjava

ASKER

Yes, I do use glade and It did not help to use delete_event or gtk_widget_destroy or setting the popup window to NULL.

Here is the callback:

gboolean fof_delete_event(void)
{
  gtk_widget_hide(filefoferrorbox);
  filefoferrorbox = NULL;
  return TRUE;
}

OR:

gboolean fof_delete_event(void)
{
  gtk_widget_hide(filefoferrorbox);
  return TRUE;
}
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
filefoferrorbox is a GnomeMessageBox and therefore has no parent.
copy paste around 10 lines of code before and after line 1427

my guess is that in the callback

gboolean fof_delete_event(void)
{
 gtk_widget_hide(filefoferrorbox);
 filefoferrorbox = NULL; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 return TRUE;
}

you set filefoferrorbox to NULL and then you try to access it in line 1427