GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 18, 2014 6:14 pm

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: gtkmm (Linux): hide_all() doesn't quit child window?
PostPosted: Thu Jul 05, 2007 6:56 pm 
Offline
Familiar Face

Joined: Thu Jul 05, 2007 6:10 pm
Posts: 9
Hello,

actually I have three problems but for now I want to solve this one:

I have a main window. From this main window, I can open a second window which must not be modal (so Gtk::Dialog is no solution).
When I close the second window and then the main window, everything works good but when I close the main window first, the second window will be closed in fact but the program doesn't exit. I see that ony my console. The prompt doesn't appear.
When I don't use Gtk::Main::run(second) it works, but the container won't be filled with the child widgets. The container stays empty.
When I use Gtk::Main::run on the second window, I have this problem from above. What can I do? (the comments with "senseless" were tries of mine to solve the problem but without effect)
Here is my code example:


Code:
void GUIMenu::onExitClick()   {
    matrixWindow.hide_all();    //senseless
    hide_all();
}

//this method will be called on clicking a button in the main window
//it opens the second window
void GUIMenu::onInputClick()   {
    Gtk::Table table;
    Gtk::HBox hbox;
    createTable(table);
    matrixWindow.set_title("Adjazenzmatrix");
    matrixWindow.property_destroy_with_parent();  //senseless
    hbox.pack_start(table);
    matrixWindow.add(hbox);
    matrixWindow.set_resizable(false);
    matrixWindow.show_all();
    Gtk::Main::run(matrixWindow);
}

void GUIMenu::onMatrixClick(int j, int i)   {
   //some code
}

//private
void GUIMenu::createTable(Gtk::Table &tab)   {

    int knotenAnzahl = spinbutton.get_value_as_int();
    for(int i = 0; i < knotenAnzahl; i++)    {
        for(int j = 0; j < knotenAnzahl; j++)   {
              Gtk::Button* pButton = Gtk::manage(new Gtk::Button(" 0 "));
              tab.attach(*pButton, j, j+1, i, i+1);
       
               pButton->signal_clicked().connect(sigc::bind<int, int>
                    (sigc::mem_fun(*this, &GUIMenu::onMatrixClick), j, i));
          }
      }
}


Btw: I could use an exit(0) command in the onExitClick method and it works then but I want to avoid such methods to quit the program.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 7:25 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
hide_all() only hides a window from view. It does not destroy the window or exit the application. You have to call gtk_widget_destroy() to delete the window, or gtk_main_quit() to exit the application. (Those two functions are GTK+ with C, so you'll have to look up the Gtkmm functions.)

You hand off control to GTK+ with gtk_main(), which continues until you quit the main loop with gtk_main_quit(). In your code, you are neither destroying any window, nor quitting the application.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 7:45 pm 
Offline
Familiar Face

Joined: Thu Jul 05, 2007 6:10 pm
Posts: 9
Thanks for your fast answer, but that's exactly the problem. I don't know how to quit it. In every example I saw, they use this stupid hide().
I read that Gtk::Main::quit(); should do the job, but if I use it in the onExit-method, I get no effect.
The prompt doesn't appear until I press STRG + C.
I don't understand why this is so complicated to quit a simple program.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 05, 2007 8:23 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Ok, first. GtkDialog does not have to be modal. If you call run(), it will be modal. However, if you just connect to the response signal, it won't be modal.

The reason that the children aren't shown when you don't call run() is because that function calls show_all() on the dialog. You will have to call that yourself (possibly on the dialog's internal Gtk::VBox.

gtk_run() also creates a new main loop to implement the modal aspect of the dialog, so that would be a problem with your application. You shouldn't use run(), but use the response signal method. Then, use destroy() to make your windows go away rather than hide(), since hide() will only take them from the user's view, rather than destroy them. You can then use your Gtk::main::quit() function to exit the application.

To someone that is new to GTK+, it seems like a pain to quit the application, but it really does make perfect sense in terms of the underlying GLib main loop. The main loop is the reason that you have signals/events in GTK+. In fact, you can compile against just GLib, and use its main loop directly, which is used by GTK+'s main loop for the internal structure.

The point is that, you setup your application. Then, you start the main loop with gtk_main(). This function polls for X events and signals from the application, calling the corresponding callback functions when they occur. Even if you don't create any widgets, the application will continue to chug along. So, the application will not quit until all main loops are stopped (you can create a stack of main loops, but only the most recently created loop will have control.)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 4:16 am 
Offline

Joined: Thu May 31, 2007 9:31 am
Posts: 1
Can you suggest me a good book on GTK+


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 12:39 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
The only book on GTK+ 2.x that is written is the one I just released in April, Foundations of GTK+ Development.[/url]

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 4:49 pm 
Offline
Familiar Face

Joined: Thu Jul 05, 2007 6:10 pm
Posts: 9
openldev wrote:
The reason that the children aren't shown when you don't call run() is because that function calls show_all() on the dialog. You will have to call that yourself (possibly on the dialog's internal Gtk::VBox.


I tried show_all() on every widget, even on every button itself, but how can it be different, no effect.
By the way, it's not a dialog but a Gtk::window.


Quote:
gtk_run() also creates a new main loop to implement the modal aspect of the dialog, so that would be a problem with your application. You shouldn't use run(), but use the response signal method. Then, use destroy() to make your windows go away rather than hide(), since hide() will only take them from the user's view, rather than destroy them. You can then use your Gtk::main::quit() function to exit the application.


Yes, I always thought that hide() just "simulates" an exit. But there is no destroy()-method. Actually there is a destroy_() method but it's protected and not public.

Quote:
To someone that is new to GTK+, it seems like a pain to quit the application, but it really does make perfect sense in terms of the underlying GLib main loop. The main loop is the reason that you have signals/events in GTK+. In fact, you can compile against just GLib, and use its main loop directly, which is used by GTK+'s main loop for the internal structure.


That sounds a little bit tricky.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 5:32 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Check out the Description section of this page: http://developer.gnome.org/doc/API/2.0/ ... #id2561959

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 08, 2007 8:45 am 
Offline
Familiar Face

Joined: Thu Jul 05, 2007 6:10 pm
Posts: 9
In this text is written that one should use exit() instead of gtk_exit().
Now, I did do that in this way. First I was afraid that system ressources won't be freed, if I just abort with exit but they'd probably know it better and obviously the system ressources will be really freed. That was originally my main concern.
Now, I will let it in this way.


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group