I have a 'mygtk' library that performs various functions to make writing my gtkmm applications easier. I have converted the library to gtkmm 4 and am having problems displaying a window from the application. The window is to be displayed upon an entry validation error and shows an error message advising what the problem is. I can dynamically create the dialog ok, have set up signal handlers for any buttons and now simply want to show it. When I use dialog->show() all I see is the window and title that I have given it but without any widgets displaying. The code that I am using is the below where DLG is the dialog that I have dynamically created and set up handlers for buttons etc.
Gtk::ResponseType MyGtk::Dialog_Show_All_And_Run(Gtk::Window *dlg)
{
Gtk::ResponseType gtk_response;
//
// First we must ensure that the dialog is not null before we attempt
// to de - reference it.
//
assert(dlg);
//
// Next we must show all of the widgets in the dialog DLG.
//
Widget_Show(dlg);
//
//Now we need to obtain a lock the dialog/response semaphore. This will
//be unlocked once the above callback handler has set the response into
//the return response variable.
//
Dialog_Response_Semaphore_Lock();
//
// Now we need to convert the returned response to a gtk reponse so we
// can subsequently return it.
//
gtk_response = static_cast<Gtk::ResponseType>(i_dialog_response);
//
//Now that we have fetched the dialog/response from the callback
//handler, we can now unlock the semaphore and return it to the
//initial state.
//
Dialog_Response_Semaphore_Unlock();
//
//Finally, we can return the response to the caller.
//
return gtk_response;
}
The 'widget show' routine simply does a dlg->show() for gtkmm 4. I am using semaphores to stop the displayed window from exiting immediately. The idea is that the initial state of the semaphore is such that the 'lock' call will have to wait until the button handler sets the dialog response into i_dialog_response and then does an unlock. This will cause the 'lock' to succeed and then the above can fetch the response, unlock the semaphore to return it to its initial state and then return the response. Under gtkmm 3 this worked fine but something in my code is wrong for gtkmm 4. Hvae no idea what and have tried GTK_DEBUG=interactive on one of my applications that uses the 'mygtk' library and I can see the application window. When I enter some invalid data into an entry and then hit return the dialog is supposed to pop up with an error message. What I am seeing is that the window pops up, shows the title and no widgets. I write in C++ but if anybody can help, a C example would clarify what I am doing wrong.
Put in debug code to ensure that widgets are being created in the dialog and that the gtkmm 4 code now uses 'set_child' and not 'add' as per gtkmm 3. Tried GTK_DEBUG=interactive when running one of my applications and can see application window, but when dialog displays window and title, I cannot see this window to see what is going on.
Further to the above, I finally worked out what I was doing wrong. It was rather simple really. In the Dialog_Show_All_And_Run() function I created a Gtk::Application object, added the window DLG to it and then did an app->run(). All works fine and the semaphores were only confusing the issue and turned out not to be needed. Don't know if this is the best solution but at least it works for me. Wouldn't mind any comments re whether this is the best way to solve the problem.
Change the Dialog_Show_All_And_Run()
function to remove the semaphore code.
Create a new Gtk::Application
object, add the window DLG, then run it via app->run()
.