Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:39:57+00:00 2026-06-11T23:39:57+00:00

I have a main window with a menu wich opens another window. This secondary

  • 0

I have a main window with a menu wich opens another window. This secondary window has a button Close. That button has the signal clicked connected. My problem is that I don’t know how to close/destroy that parent window. I have tried with gtk_widget_destroy, but an error appears because window is not a widget …. I haven’t found any function to destroy the parent window ….

Can anyone show me the way, please?
Thanks in advance.

———————————————–

Ok. I post a piece of code. When I execute the program I click in “Open window” button. A new window is openned with one button “Close”. If I click in “Close” button I get next error in terminal: (Windows:13801): Gtk-CRITICAL **: gtk_widget_destroy: assertion `GTK_IS_WIDGET (widget)’ failed

The code is:

#include <stdlib.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

void open_window(GtkWidget *widget, gpointer window);
void close_window(GtkWidget *widget, gpointer window);

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *fixed;
    GtkWidget *button;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Windows");
    gtk_window_set_default_size(GTK_WINDOW(window), 230, 150);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

    fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed);

    button = gtk_button_new_with_label("Open window");

    gtk_fixed_put(GTK_FIXED(fixed), button, 50, 50);
    gtk_widget_set_size_request(button, 80, 35);

    g_signal_connect(G_OBJECT(button), "clicked",
                     G_CALLBACK(open_window), G_OBJECT(window));

    g_signal_connect_swapped(G_OBJECT(window), "destroy",
                             G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;

}


void open_window(GtkWidget *widget, gpointer window)
{
    GtkBuilder *builder;
    GtkWidget *secondWindow = NULL;

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "secondWindow.glade", NULL);

    secondWindow = GTK_WIDGET (gtk_builder_get_object (builder, "secondWindow"));

    gtk_builder_connect_signals (builder, NULL);

    g_object_unref (G_OBJECT (builder));

    gtk_window_set_modal(GTK_WINDOW(secondWindow), TRUE);
    gtk_widget_show_all(secondWindow);
}

void close_window(GtkWidget *widget, gpointer window)
{
    gtk_widget_destroy(GTK_WIDGET(window));
}

In file “secondWindow.glade” is defined a window, a table and a button placed in the middle cell of the table. Also, it is defined a handle for the “clicked” event button named “close_window”.

Link to glade file if anyone wants to execute it: https://sites.google.com/site/marvalsiteimages/secondWindow.glade

I hope this could help you to understand my problem.
Thansk.

————————————————-

Final code based on the response:

void open_window(GtkWidget *widget, gpointer window)
{
    GtkBuilder *builder;
    GtkWidget *secondWindow = NULL;
    GtkWidget *closeButton = NULL;

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "secondWindow.glade", NULL);

    secondWindow = GTK_WIDGET (gtk_builder_get_object (builder, "secondWindow"));
    closeButton = GTK_WIDGET (gtk_builder_get_object (builder, "closeWindowButton"));

    g_signal_connect (G_OBJECT (closeButton),
                      "clicked",
                      G_CALLBACK (close_window),
                      G_OBJECT (secondWindow)); // here is the magic: the callback will get the window to close

    g_object_unref (G_OBJECT (builder));

    gtk_window_set_modal(GTK_WINDOW(secondWindow), TRUE);
    gtk_widget_show_all(secondWindow);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:39:58+00:00Added an answer on June 11, 2026 at 11:39 pm

    Your problem is that the “clicked” signal of the button of the second window is connected from the glade file. But the signal handler needs a pointer to the window to destroy it. This is passed through the “user_data” parameter of the signal callback.

    One way would be by passing the second window as the user_data argument in Glade (give a look at this Glade tutorial), but the argument is supposed to be a pointer, and I don’t know how one can do it with glade. EDIT: just click on the user data field associated to this signal in glade, and a popup will allow you to select the object to pass to the signal handler. Just select your “secondWindow” object.

    Another way to do it would be to just remove the signal handling from the glade file, and connect manually the clicked signal from code, passing a pointer to the second window as user data:

    void open_window(GtkWidget *widget, gpointer window)
    {
        GtkBuilder *builder;
        GtkWidget *secondWindow = NULL;
        GtkWidget *closeButton = NULL;
    
        builder = gtk_builder_new ();
        gtk_builder_add_from_file (builder, "secondWindow.glade", NULL);
    
        secondWindow = GTK_WIDGET (gtk_builder_get_object (builder, "secondWindow"));
        closeButton = GTK_WIDGET (gtk_builder_get_object (builder, "closeWindowButton"));
    
        g_signal_connect (G_OBJECT (closeButton),
            "clicked",
            G_CALLBACK (close_window),
            G_OBJECT (secondWindow)); // here is the magic: the callback will get the window to close
    
        g_object_unref (G_OBJECT (builder));
    
        gtk_window_set_modal(GTK_WINDOW(secondWindow), TRUE);
        gtk_widget_show_all(secondWindow);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window, that opens another window. I want to close this
I have a main menu window. On clicking any menu item it opens a
I have main window which has inner grid components. When I press a button
I have in my main window 2 triggers 1. from the menu that closed
How do I create a Motif main window that doesn't have a system menu,
I have come across this Cocoa application (source code) that shows a main Window.
I have a main window with a Gtk Button named openDialog. If I click
I have a window(say main window) with a frame which has a page in
i have a mvvm app that the main window is a tab control. i
I have an application with a main window that loads in text file(s) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.