Important: Please read the Qt Code of Conduct -

Creating exit button for a window

  • Hello.

    I created two windows. One shown, the other hidden.
    A button on window 1 to show window 2.

    I'd like to make a "hide" button on window 2 for window 2.

    I connected the "hide" button like this:

    QObject::connect(closeBtn, SIGNAL(clicked()), qApp, SLOT(quit()));

    It quits totally the app, but I want window 1 to stay open.

    Isn't there something similar to close a single window?

    Then I tried using win2.hide(); within a slot but it says "'win2' was not declared in this scope", even all .h files included.

    Can anybody point me in the right direction?

  • Found it:

        QObject::connect(exitBtn, SIGNAL(clicked()), this, SLOT(exitSlot()));
    void window2::exitSlot()

  • Qt Champions 2019

    @Shodan close() is a slot, so you can connect it directly without creating one more slot :-)

  • Thank you for the tip ;-)

Log in to reply