[GTK4 C Windows] cannot save using gtk_file_dialog_save

Hello, I’m using GtkFileDialog that replaces GtkFileChooser and if it is ok with file opening, I have an exception when I try to use gtk_file_dialog_save(). Error message is the same that I had previously when I tried to deploy my executable.

(Project3.exe:4256): GLib-GIO-ERROR **: 16:47:39.063: No GSettings schemas are installed on the system

On Linux it works fine. It may is due to a missing binary ressource but I don’t know what it can be as I already put all dlls from my gnome build bin directory into my application directory.

I’m using code from gtk demo print_editor and it can save, but if I put its .exe file into my application directory it doesn’t work just as my app.

I’m really sorry to bother you with my windows problems.

Hello, Gilbert! How did you compile the GTK bundle on Windows? Are you using MSYS2, gvsbuild or Meson subprojects?

To fix the issue, just execute glib-compile-schemas:

  • From a Command Prompt (or PowerShell) as glib-compile-schemas ..\share\glib-2.0\schemas
  • From a MINGW64 shell as glib-compile-schemas /c/path/to/share/glib-2.0/schemas

Let me know if you find any difficulties!

Thank you. I compile GTK using Meson, I followed Collabora’s blog post. But as I didn’t manage to compile my app using meson too, I simply added includes of the GTK bundle to Visual Studio C/C++ other includes directory parameter, its lib directory to the general library directory parameter and its bin directory to the general executables directory parameter.

What I want to do is not making my application runnable on my machine, this worked fine with Code::Blocks, but to have an executable that I can deploy. Apparently the problem is with glib-compile-schemas as you said.

I tried to run the command you gave, from a xNative Tools command prompt (VS 2022 console) on my application directory (project\x64\Release) and as parameter enought …\ to reach GTK build share directory. It ran but after when I tried my app, the same error occurs when I try to save.

One more thing, my app uses temp directory to save data if the user didn’t choose a file to save and this temp save works, I can even use the file with app’s load menu action, this behaviour could maybe help.

I also used VS Extension to create a setup project using my app project, and it produces a working setup. Apparently it analyses the project and adds dll resources it needs. Here are the dll it added :

  • cairo-2.dll
  • gio-2.0-0.dll
  • glib-2.0-0.dll
  • gobject-2.0-0.dll
  • gtk-4-1.dll
  • VCRUNTIME140.dll

It GtkFileDialog.save() function doesn’t work on Windows for the moment, I can replace it by something more rough like an inputbox.

This has nothing to do with the API: the file selection dialog has settings, which require installing the GTK schemas alongside your application’s own settings, and then running glib-compile-schemas.

I would be happy to be able to install GTK schemas alongside my application’s settings, I tried to do that several times, one hour ago I tried again, glib-compile-schemas ran without complaining, but my app and every other application Gtk4 application using GtkFileDialog.save() behaves the same (GtkFileDialog.open() works). Before that, before the deprecation, I was able to save (I’m doing it into my demo video at 8:40) from a fresh compiled application on my windows development pc. On my setup application I can easily run any needed script to install what is needed. For sure I’m a long way to understand how GTK works, I’m slowly reading the code but I just bumped into

 g_return_if_fail (GTK_IS_FILE_DIALOG (self));

without being able to dig deeper into the code as I didn’t manage to find GTK_IS_FILE_DIALOG which seems to be a macro but I didn’t find any information about it.

That precondition check means you’re passing a pointer either to the invalid instance, or to some random garbage.

It’s a type check inline function generated by G_DECLARE_FINAL_TYPE in gtkfiledialog.h:

G_DECLARE_FINAL_TYPE (GtkFileDialog, gtk_file_dialog, GTK, FILE_DIALOG, GObject)

For more information, please read the GObject tutorial.

Ok, I think I get it, I only searched for “GTK_IS_FILE_DIALOG” and was suspecting that it was something more sophisticated like that without being able to find it. What I’m looking for is the context that causes the GLIB-GIO Error “No GSettings Schemas are installed on the system”, but for the moment I’m using a simple fallback that saves without using the FileDialog. For the moment I only took a look at the last part of the GObject tutorial about signals, I will read it all, but I’m afraid it’s too much information for me.

The “context” is:

the file selection dialog has settings, which require installing the GTK schemas alongside your application’s own settings

If you don’t install the org.gtk.Settings.* XML schemas alongside your application’s settings schemas, and you don’t compile all of them with glib-compile-schemas, then GTK won’t find the schemas, and assume that the installation is broken—which it is—and abort.

What do you call an installation ? Is there a place where the files that needs to be installed alongside the application settings schemas are detailed ? I mean that I cannot invent and that’s why I’m trying to read the code to understand what’s missing.

I’ve got an “installation” on my pc that works, when I log on the user account that I use to compile, it works with Code::Blocks using MSys2 and also with Visual Studio 2022 using MSVC (build from meson). I certainly need to use meson to build my application with MSVC, but I didn’t managed to use the Collabora’s blog post detailing how to do it, so I’m compiling on MSVC using the GUI and I configured the include lib and bin directories. There is certainly something that I’m missing regarding the GSettings Schemas. I ran glib-compile-schemas on my application directory (what you call alongside my application). What I didn’t do is to put the org.gtk.Settings. XML files (I saw them while looking for GTK_IS_FILE_DIALOG), I’m going to do that (but need to log out from Linux where I write this to run Windows).

Yes, that’s an installation—as opposed to “running the binary you just compiled from the build directory”. You need to install the binary and all the other files in the directory layout that is expected by GTK and its dependencies.

1 Like

So what I need to do is create the directory layout that is expected by GTK, I think that the setup project can be configured to do that, and I think it already put the dependencies, and if I have a proper Gnome installation I could put the icons there, it’s a problem that I have, some of them are missing. I’m heading into that direction.

Following your advice to create an installation, I added a share folder to my application folder with the contents of my GTK4 build share folder, then I ran glib-compile-schemas. Finally I created a setup program with Visual Studio with this installation, and tried it on another Windows account. It works even if I still have some problems due to my lack of experience with all those tools :

  • I still don’t have some icons even if they are into the share\icons folder, I tried to update the icon cache (gtk4-update-icon-cache -t) but nothing changed.
  • I must get rid of the console window that launches before the application window (on Code::Blocks it was an option to check on build properties, I need to find its’ Visual Studio 2022 equivalent)

Ok, here’s a very small repo showing how to build an application and all the GTK bundle with Meson: GitHub - lb90/meson-gtk-sample

  • Open Start -> Visual Studio 2022 -> VS x64 Native Tools Command Prompt
  • Ensure that you have git and python in PATH:
    • where git
    • where python
  • git clone https://github.com/lb90/meson-gtk-sample.git
  • mkdir meson-gtk-sample-build
  • cd meson-gtk-sample-build
  • meson setup ..\meson-gtk-sample --buildtype=release --prefix=C:\msvc-bundle
  • ninja
  • ninja install

After that you should have a working bundle in C:\msvc-bundle. In C:\msvc-bundle\bin\gtk-sample.exe you have the hello world program

It also solves the two issues you’re having:

  1. No console at startup (thanks to the win_subsystem: 'windows' option in meson.build)
  2. Includes the Adwaita icon theme

Thank you, I have solve the console problem, there’s a pragma directive to add for that for MSVC. I added Adwaita icon theme but I’m certainly missing something, so I’m going to take a look at your repo. I’m slowly updating my developing abilities after more than 25 years and there are lots of changes, and Meson seems to be one of the most impressives ones.

I tried your meson sample project and it worked. Then I replaced it by my project main.c, but ninja failed with a first error saying ‘GtkFileDialog’ is undeclared identifier. On gtk subproject sources I didn’t find gtkFileDialog.c, so I edited subprojects/gtk.wrap to replace ´´´revision = 4-8´´´ by ´´´revision = main´´´ but is was not enough, my code is based on latest gtk sources, 4.9.2 at the time I did this, that I downloaded and did put into my src folder that I used to build it. Can I tell meson that the gtk subproject must use that src/gtk folder ?

1 Like

Ah, yes :slight_smile: right now gtk.wrap points to the stable branch (gtk-4-8). I have made the necessary changes in GitHub - lb90/meson-gtk-sample to point to main and also pushed adwaita-icon-theme.wrap, which I forgot to include.

In general you should update subprojects explictly, that’s explained in Subprojects. However, maybe this time it’s best to wipe out the current source / build directories and start anew.

At first I tried to explicitely point to 4-9-2 as it is specified into meson.build of the gtk sources (it’s latest version, so 4.9.1) I’m using, but this branch doesn’t exist. On the NEWS file of gtk-4-9-1 is written

Overview of Changes in 4.9.1, 31-10-2022

Note that deprecations are an early outlook at changes
that will appear in an eventual GTK 5 release, which is
still far away. We are introducing deprecations in 4.10
as a way to give users time to adapt, and to provide
feedback on our plans.

So for the moment it may is not possible for me to use that meson subprojects method, except if there’s a way to use local gtk 4.9.1 sources.

Branches use the format “gtk-major-minor” (i.e gtk-4-8), while tags use the format “major.minor.micro” (i.e 4.9.1). To point to the latest unstable release you can write

revision = 4.9.1

In the gtk.wrap file

1 Like

With the correct revision it worked very well. To build the installer executable, I suppose I can simply use the mscv_bundle folder. I use a software for that, you give it the files and it create a setup.exe. But with Visual Studio it was simpler as I only needed to create a setup project using my project solution. I am first going to try using VS setup project and if I don’t manage to use this meson subproject method by using its meson.build file to create a new solution, I will use Inno Setup.

Well, I found the meson command to create .vs project (meson setup build_dir --backend=vs2022) but it doesn’t work, so I simply make a setup.exe using Inno Setup and it worked.

1 Like

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