Re: best way to use multiple windows



Thiago Guzella wrote:

> Greetings everyone,
>
>
> I am writing a simple GTKmm (btw, GTKmm 2.4) application, which has a
> main window, a menu, etc, using glade (just to place the widgets).
> Some options in the menu (such as "preferences") are required to open
> a modal window, with apply and revert buttons, allowing the user to
> tweak the app; pretty straightforward :)
>
> My question is: what is the best way to implement such feature? should
> i make the "preferences" window a member variable of the main window
> class, create it (i.e.: alloc memory) when it is requested?? if so,
> how should i handle the window closing? my first guess would be to
> send a signal to the main window to hide the preferences window and
> release the memory used by it, so that the main window will regain
> focus.

Well, my approach to this problem is to make all subwindows normal
member-varables of their parents. This may result in some memory
overhead, but it keeps things simple, especially, when your subwindow
communicates with your parent via sigc::signals. The application i'm
working on has dozens of subwindows and needs about 20 MB of memory when
no file is opened, while a  a completly plain window, without a single
button, box or something else, needs slightly more than 14MB on my system.

Thus, i think it may be too much work with too little advantages to
new/delete your subwindows as needed, allthhough this still remains
interesting. Maybe someone with more insights to gtkmm/gtk internals
than me can give us some advise. If i would implement such a behavour,
my first try would be to override on_hide() like this [that is just a
guess, never tried it]

void SubWindow::on_hide()
{
       Gtk::Window::on_hide();
       m_sig_hide.emit(); //you parent should connect to this signal and
delete your window
}

However, i would not be surprised if that leads to a SIGSEGV, as the
window, and m_sig_hide will be deleted before the function exits ....

Antonio



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]