Can't close "dialog" window from code

I have a small dialog window for editing some properties subclassing GtkWindow

<template class="AircraftDialog" parent="GtkWindow">

I also have a ‘Cancel’ and and ‘Ok’ button, but as soon as I add a handler to my button e.g.

impl ObjectImpl for AircraftDialog {
        fn constructed(&self) {
            self.btn_cancel.connect_clicked(clone!(@weak self as window  => move | _button | {

the window will not close. It won’t close if I press the button or if I press the close box on the window frame.

I presume the reference, although specified as @weak is somehow preventing the closure. A bit of a mystery how to proceed, especially in the “Ok” case.

You are probably storing a strong reference to the window from somewhere else, e.g. having a dialog field in other struct.

Have you connected a callback on the window’s close-request signal?

If yes, make sure it returns false to allow closing the window.

No I haven’t connected any other callback, especially not close-request.

I have found a work around, which was to set hide_on_close to true and dispose of the window manually, which doesn’t answer the question of why it would not close otherwise.

No I am not storing any other reference to the window, and if I remove that one call back shown above it does close (using the ‘x’ in the frame)

Did you try to define let window = self.obj() and then pass window thru a weak ref @weak window => move ...?

Another thing I am really missing is that you dont call self.parent_constructed() at the start of constructed

Thanks @Maximiliano , It is the missing self.parent_constructed() call. My bad. Added that and works as expected.

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