Problems with converting app from gtk-rs(GTK3) to gtk4-rs(GTK4)

Recently I wanted to test if my app is easily convertible to GTK4 from GTK3, but looks that there are a lot of problems with conversion.
I checked and found only a few entries from Gtk – 4.0: Migrating from GTK 3.x to GTK 4, so it is possible that I missed some.

I prepared some conversion tips for my project but not know if all things are proper, and errors which I couldn’t fix.

Errors

What happened to gtk4::WindowPosition ? - missing in gtk4-rs source
gtk4::main and gtk4::main_quit don’t exits, use ApplicationWindow now?
resize is missing, xlib is required now(not sure about api) - TODO I used this for fitting window size to content, maybe similar method exists?
run is missing in Dialog - probably needs to implemented as closure
children dialog no longer returns childrens, can’t find alternative version of this function
connect_key_release_event and connect_button_release_event in Button are missing
FileChooserDialog::with_buttons is missing
connect_delete_event missing in Window
set_relative_to is missing in Popup (probably should exists but only for MenuButton widgets)
with_label_from_widget missing in CheckButton
hide_on_delete missing on Window
connect_clicked missing on CheckButton
add in Box, cannot add grid (append will work?)

Refactor

show_all method is missing - all widgets are visible by default so remove all occurrences of this - TODO Probably some usages of show_all should be changed to only show
Treepath no longer can be displayed with {}
set_select_function don’t need to be boxed
buffer.text() returns valid text, so match can be removed around such statements

Replace

gtk:: with gtk4::
RadioButton with CheckButton, groups needs to be implemented manually
ButtonBox with Box
use gtk4::prelude::*; with use gtk4::prelude::*;use gtk4::prelude::*;use gtk::Inhibit; - looks that now this isn’t in prelude, probably can be added also in GTK3

.value( with .get( - TreeModel - this will broke examples from below
scale_similarity_similar_images.get() with scale_similarity_similar_images.value()
scale_similarity_similar_videos.get() with scale_similarity_similar_videos.value()

.buffer().unwrap() with .buffer() - TextView always return valid thing

.path(&iter).unwrap() with .path(&iter) - Treemodel, looks that always return valid thing
model.path(&current_iter).unwrap() with model.path(&current_iter) as above
model.path(&next_iter).unwrap() with model.path(&next_iter)

window_main.set_title("Czkawka") with window_main.set_title(Some("Czkawka")) - title can be empty

Indeed, you missed a bunch. :smiley:

The WindowPosition enumeration was implemented client-side inside GTK, and since there are no global coordinates available in all windowing system backends, has been removed.

Yes: Gtk – 4.0: Migrating from GTK 3.x to GTK 4

The short answer is: don’t do that. The window size should be able to fit the minimum size of the content; anything else is based on the natural size, and that can be arbitrarily large.

No, it doesn’t: Gtk – 4.0: Migrating from GTK 3.x to GTK 4

Connect to the “response” signal, and call present().

If you are implementing a widget, then use the GtkWidget API: first_child(), next_sibling(), previous_sibling(), last_child(). If you are not implementing a widget then you should not be iterating over the children in the first place, as the children list can include additional internal children. If you want to keep track of children you add to a container, you should keep a reference to them yourself.

I strongly recommend going through all the items in the migration guide.

The rest of the items look related to the Rust bindings.

1 Like

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