Gtk_file_chooser_dialog_new and schema error

I follow pretty much the example from here:
GtkFileChooserDialog: GTK 4 Reference Manual, copy-paste.

When i call gtk_file_choose_dialog new, I get the error:
Settings schema ‘org.gtk.gtk4.Settings.FileChooser’ does not contain a key named ‘view-type’

But when I look into org.gtk.gtk4.Settings.FileChooser:

$ grep view-type /usr/share/glib-2.0/schemas/org.gtk.gtk4.Settings.FileChooser.gschema.xml

It’s there. I have reinstalled libgtk4-common which is the package that provides thsi file.

How do I get around this? I have seen others having this problem but haven’t been able to find a solution. Any suggestions?

First of all, that documentation is an old snapshot; you want the official API reference.

Second of all: GtkFileChooserDialog is deprecated with GTK 4.10, and it does not work in a sandboxed environment. You either want to use GtkFileChooserNative (which has also been deprecated in 4.10), or better GtkFileDialog.

The view-type key was added in GTK 4.10, but it seems you’re trying to run your code against an older version of GTK.

How did you install GTK? Which version is available on your system? How are you building your application?

My gtk4 installation comes with ubuntu. I used to compile my own until gtk4 came with the distribution.

Yes, I am aware of that “proper” documentation but I have never been able to get anything useful out of it. At least I got a fairly large application using the old documentation, at least until now.

My build relies on pkg-config --cflags gtk4 and related (–libs and glib-2.0 or course).

According to dpkg:
ii libgtk-4-1:amd64 4.10.3+ds-0ubuntu1 amd64 GTK graphical user interface library
ii libgtk-4-bin 4.10.3+ds-0ubuntu1 amd64 programs for the GTK graphical user interface library
ii libgtk-4-common 4.10.3+ds-0ubuntu1 all common files for the GTK graphical user interface library
ii libgtk-4-dev:amd64 4.10.3+ds-0ubuntu1 amd64 development files for the GTK library

So, 4.10. The rest of the build is make, gcc.

That’s immaterial: the old developer docs are a snapshot, and they won’t ever be updated. This means you’re looking at a snapshot of how GTK 4 looked like 3 years ago, when 4.0.3 was released. There have been 5 minor releases since then.

DId you build GTK4 at any point? Do you have a previous GTK4 installation in /usr/local?

I guess it is a problem for me then because I cannot get anything useful out of the current doc.
I still do have my old build but its hidden in a very non-standard place (/opt/local) specifically for the purpose to not find it by accident. There is nothing in /usr/local/lib/x86_64-linux-gnu and nothing in or points to /opt/localc. ldd only points to the proper libraries.

Do you have anything under /usr/local/share/glib-2.0/schemas? Do you have any gschemas.compiled somewhere that is not /usr/share/glib-2.0/schemas? Did you use glib-compile-schemas on your system? Are you overriding GSETTINGS_SCHEMADIR, XDG_DATA_DIRS, or XDG_DATA_HOME in your environment?

The library has really nothing to do with schemas: they are shipped by the library, and “compiled” on the system by your package manager. If Ubuntu is shipping GTK 4.10, then the schema should have the view-type key, and installing the package should have compiled the correct schema.

There was actually something in /usr/local/share/glib-2.0/schemas. I found another org.gtk.gtk4.Settings.FileChooser.gschema.xml which did not contain “view-type”.
I do seem to overwrite XDG_DATA_DIR: XDG_DATA_DIRS=/usr/share/gnome-xorg:/usr/share/gnome:/home/jarek/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop, but not the others.

I have no clue about schemas and what it is. I don’t remember ever dealing with that before so I doubt I ever compiled “one”.

I think I will try to get the gtk_file_dialog thingy to cooperate anyway.

I see now that I use gtk_file_dialog_save(), I get exactly the same crash. Moving /usr/local/share/glib-2.0 to something else solves this. The rest of the errors are obviously on me. Do I really need the stuff under /usr/local/share? I don’t even know where it comes from.

Settings schemas define the names and types of keys for GSettings; GTK has a few of those.

That’s because it’s usually handled by your package manager, not by you. You only need to deal with your own settings, and your own schemas.

Delete that file. You probably built and installed GTK4 from source at some point, and used the default prefix of /usr/local.

Once you deleted that file, run:

glib-compile-schemas /usr/share/glib-2.0/schemas

as root; or, if you want, reinstall the libgtk-4-1 package from your distribution, which will take care of compiling the schemas for you.

Thanks a lot for all help. This has been bugging me for some time.

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