GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GTK+ Win32 Application Wont Close

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
axpen
Familiar Face


Joined: 27 Aug 2007
Posts: 14

PostPosted: Mon Aug 27, 2007 10:56 pm    Post subject: GTK+ Win32 Application Wont Close Reply with quote

Ok after spending most of a day actually getting GTK to compile on my windows box I ran into a snafu. Basically when I run my application it looks and acts like normal, however when I close it, the window does close, but the program stays in memory. By this I mean I have the task manager open and run my program base.exe (from the OFFICIAL GTK+ tutorial) and when I close the window the base.exe stays in memory, indefinitely. Does anyone know what would cause this?

My environment is that of MinGW and MSYS with Tor Lillqvist GTK Win32 libs (sorry no link, first post). I proceed to compile the way the tutorial tells me to with the following makefile (i've tried hand coded too):
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

CC = /mingw/bin/gcc
PKGFLAGS = `pkg-config --cflags --libs gtk+-2.0`
WIN = -mwindows -mno-cygwin
CFLAGS = -Wall -O2 $(WIN)
SRC = base.c
LIBS =
EXE = base.exe

.PHONY : clean strip
all: $(EXE)

$(EXE) :
    $(CC)  -o $(EXE) $(SRC) $(CFLAGS) $(PKGFLAGS)

clean:
    rm -f $(SRC:.c=.o)

strip:
    strip $(EXE)

My Source is as follows:
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

#include <gtk/gtk.h>

int main( int argc, char **argv ) {
    GtkWidget *window;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_show (window);

    gtk_main ();

    return 0;
}


So again, any help would be very much appriciated,
--Alex
Back to top
deusvede
Familiar Face


Joined: 13 Feb 2007
Posts: 29
Location: Madrid, Spain

PostPosted: Tue Aug 28, 2007 5:54 am    Post subject: Reply with quote

You have to link the 'destroy' signal that is emitted when you click on the close button with gtk_main_quit(), so the GTK+ main loop ends. Your code will look as follows:
Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <gtk/gtk.h>

int main( int argc, char **argv ) {
    GtkWidget *window;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (destroy), NULL);
    gtk_widget_show (window);

    gtk_main ();

    return 0;
}

static void destroy (GtkWidget *window, gpointer data)
{
  gtk_main_quit ();
}
Back to top
axpen
Familiar Face


Joined: 27 Aug 2007
Posts: 14

PostPosted: Tue Sep 18, 2007 9:03 pm    Post subject: Reply with quote

Thank you, I realized this after reading the next step, but i'm one of those people who don't like to move on without understanding and making a previous lesson work. Thank you very much it works perfectly now :D
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP