Results 1 to 3 of 3

Thread: main window close not working

  1. #1
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default main window close not working

    new on forum, be gentle, thx for help.
    qt version 4.6.2

    This is code:

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
    {

    closeButton = new QPushButton("close");
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
    setCentralWidget(closeButton);

    bool x = false;
    // here is problem
    if ( !x )
    close();
    }

    Q: why doesn't MainWindow closes?

  2. #2
    Join Date
    Apr 2010
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: main window close not working

    Very simple.
    In the doc it says:
    Closes this widget. Returns true if the widget was closed; otherwise returns false.

    First it sends the widget a QCloseEvent.
    And a close event will be accepted by a visible widget.
    A widget gets to be visible after it got a QShowEvent, and since you are still in the constructor, no such event has been received, hence the widget is not yet visible, hence, no effect of close().

  3. The following user says thank you to Oximoron for this useful post:

    hvranic (17th June 2010)

  4. #3
    Join Date
    May 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: main window close not working

    Qt Code:
    1. #include<qapplication.h>
    2.  
    3. connect(closeButton, SIGNAL(clicked()), qApp, SLOT(quit()));
    To copy to clipboard, switch view to plain text mode 

    this works

Similar Threads

  1. Replies: 9
    Last Post: 16th May 2010, 16:21
  2. How to close two main windows at a time
    By soumya in forum Qt Programming
    Replies: 7
    Last Post: 4th February 2010, 16:12
  3. Replies: 11
    Last Post: 11th August 2008, 09:14
  4. Replies: 15
    Last Post: 23rd March 2007, 16:16
  5. How to close all windows that were created in main()?
    By Mister_Crac in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2006, 10:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.