[gtk4] gtk_widget_show() doesn't show widget

Hello!

I’m a gtk newbie and was trying to create a file chooser dialog. Please have a look at this program.

$ gcc filechooser.c $(pkg-config --cflags --libs gtk4) -o filechooser
$ ./filechooser
GTK-Message: GTKDialog mapped without a transient parent. This is discouraged.
$

It just shows this above warning message. I expected to see the file chooser dialog too. What am I missing?

Thanks!

I have a working example of a gtk4 file chooser dialog here:

http://ssalewski.de/gtkprogramming.html#_filechooserdialog

Note that you have to add the buttons yourself in GTK4, maybe that is your main issue. Well I created an application window first, I am not sure if launching a dialog from program startup works when there is no parent window. Note: When you use GTK4, you may consider using the modern app style and not the legacy program shape with gtk_init().

1 Like

You aren’t even running any main loop. All gtk applications must either be a GtkApplication or just run the mainloop themselves, like the tests in GTK do: https://gitlab.gnome.org/GNOME/gtk/-/blob/master/tests/listmodel.c#L230-231

2 Likes

Thanks! This fixed the issue.

This was originally a gtk3 program which didn’t have any loop or GtkApplication. Anyways, adding g_main_context_iteration() in loop helped. :slight_smile:

BTW, I see the filechooser dialog now but when I press Ctrl+L it says “Enter location or URL” but then when I type location e.g. /home/user/Downloads/foo etc. it starts searching for the entered text instead of treating it as a location path.

Ah, there is an open issue regarding this: https://gitlab.gnome.org/GNOME/gtk/-/issues/2985

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.