TGUI Forum

General Category => Help requests => Topic started by: Kvaz1r on 09 December 2019, 10:19:02

Title: Handling signal "Closed" for ChildWindow.
Post by: Kvaz1r on 09 December 2019, 10:19:02
I have to retrieve some information from ChildWindow when it closing, but without calling destroy/0 the window doesn't disappear.

Here is MCVE:

Code: [Select]

#include <TGUI/TGUI.hpp>
#include <iostream>

class MyFrame
        window.create(sf::VideoMode(800, 600), "TGUI window");
        panel = tgui::Panel::create();
        auto b = tgui::Button::create();
        b->connect("pressed", [this]()
                auto ptr = tgui::ChildWindow::create("Test");
                ptr->connect("Closed", [this, ptr]()
                        std::cout << ptr->getTitle().toAnsiString() << '\n';
                        //ptr->destroy();  // all works if uncomment
    void main()
        while (window.isOpen())
            sf::Event event;
            while (window.pollEvent(event))
                if (event.type == sf::Event::Closed)

    sf::RenderWindow window;
    tgui::Gui gui;

    tgui::Panel::Ptr panel;

int main()

Is it correct behaviour or I am doing something wrong and there is the right way for such situation?
Title: Re: Handling signal "Closed" for ChildWindow.
Post by: texus on 09 December 2019, 18:15:53
This behavior is intentional, it allows you to block the closing of the window (e.g. to ask the user if he is certain that he wants to close it).
If the "closed" signal isn't connected then the window is destroyed when the close button is pressed, but if you connect to the signal then you have to destroy it yourself.
Title: Re: Handling signal "Closed" for ChildWindow.
Post by: Kvaz1r on 15 December 2019, 13:22:55
Right, "vetoing" mechanism. Maybe it worth to mention about the behaviour in documentation or gather such non-always obvious questions in special FAQ topic on the forum.
Title: Re: Handling signal "Closed" for ChildWindow.
Post by: texus on 15 December 2019, 13:33:38
I should probably add it to the onClose signal and at tgui::Signals::ChildWindow::Closed in the documentation. It seems like right now it is only mentioned at the destroy() ( function.

I wouldn't know which questions to best put in a FAQ. So far I only encountered a single question where I really felt that it belonged in a FAQ (because it was asked a few times already), but I didn't want to create a FAQ with only one question in it. Unfortunately I forgot where I wrote it down so I don't even know what that question was anymore :)