Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating exit button for a window
Forum Updated to NodeBB v4.3 + New Features

Creating exit button for a window

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 29.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ShodanS Offline
    ShodanS Offline
    Shodan
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ShodanS Offline
      ShodanS Offline
      Shodan
      wrote on last edited by Shodan
      #2

      Found it:

          QObject::connect(exitBtn, SIGNAL(clicked()), this, SLOT(exitSlot()));
      }
      
      void window2::exitSlot()
      {
          window2::close();
      }
      
      
      jsulmJ 1 Reply Last reply
      2
      • ShodanS Shodan

        Found it:

            QObject::connect(exitBtn, SIGNAL(clicked()), this, SLOT(exitSlot()));
        }
        
        void window2::exitSlot()
        {
            window2::close();
        }
        
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2
        • ShodanS Offline
          ShodanS Offline
          Shodan
          wrote on last edited by
          #4

          Thank you for the tip ;-)

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved