 |
GTK+ Forums Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
|
|
|
| Author |
Message |
|
|
Battlestar Gentoo Familiar Face
Joined: 05 Jul 2007 Posts: 9
|
Posted: Thu Jul 05, 2007 6:56 pm Post subject: gtkmm (Linux): hide_all() doesn't quit child window? |
|
|
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: (Plaintext) | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
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. |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 387 Location: Fairfax, Virginia
|
Posted: Thu Jul 05, 2007 7:25 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Battlestar Gentoo Familiar Face
Joined: 05 Jul 2007 Posts: 9
|
Posted: Thu Jul 05, 2007 7:45 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 387 Location: Fairfax, Virginia
|
Posted: Thu Jul 05, 2007 8:23 pm Post subject: |
|
|
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.) |
|
| Back to top |
|
 |
codebug
Joined: 31 May 2007 Posts: 1
|
Posted: Fri Jul 06, 2007 4:16 am Post subject: |
|
|
| Can you suggest me a good book on GTK+ |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 387 Location: Fairfax, Virginia
|
Posted: Fri Jul 06, 2007 12:39 pm Post subject: |
|
|
| The only book on GTK+ 2.x that is written is the one I just released in April, Foundations of GTK+ Development.[/url] |
|
| Back to top |
|
 |
Battlestar Gentoo Familiar Face
Joined: 05 Jul 2007 Posts: 9
|
Posted: Fri Jul 06, 2007 4:49 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
openldev Never Seen the Sunlight
Joined: 21 Sep 2005 Posts: 387 Location: Fairfax, Virginia
|
|
| Back to top |
|
 |
Battlestar Gentoo Familiar Face
Joined: 05 Jul 2007 Posts: 9
|
Posted: Sun Jul 08, 2007 8:45 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
Powered by phpBB © 2001, 2005 phpBB Group CodeBB 1.0 Beta 2
|