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
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?
I have a working example of a gtk4 file chooser dialog here:
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().
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
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.
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
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.