Results 1 to 2 of 2

Thread: Qt4 - How to close a window?

  1. #1
    Join Date
    May 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qt4 - How to close a window?

    Hey!

    I have a problem that I can't figure out..any help would be great

    I'm a beginner at Qt and I'm trying to figure this out but I'm getting an error

    My GUI should function such that on a specific button press a new window pops up and the old one shuts...
    I got the new window to pop up and stuff and everything works fine..but i can't figure out how to close the old one... any pointers??

    Qt Code:
    1. #include <QtGui>
    2. #include "guistart.h"
    3. //#include "addcluster.h"
    4.  
    5. // if we include <QtGui> there is no need to include every class used: <QString>, <QFileDialog>,...
    6.  
    7. guiStart::guiStart(QMainWindow *parent)
    8. {
    9. setupUi(this); // this sets up GUI
    10.  
    11. // signals/slots mechanism in action
    12. connect( nextButton, SIGNAL( clicked() ), this, SLOT( addClusterWindow() ) );
    13. }
    14.  
    15.  
    16. void guiStart::addClusterWindow()
    17. {
    18. addCluster *window = new addCluster();
    19. window->show();
    20. this.close();
    21. }
    To copy to clipboard, switch view to plain text mode 

    All my windows are QMainWindow .

    The above code gives me this error
    Qt Code:
    1. guistart.cpp: In member function ‘void guiStart::addClusterWindow()’:
    2. guistart.cpp:20:7: error: request for member ‘close’ in ‘this’, which is of non-class type ‘guiStart* const’
    To copy to clipboard, switch view to plain text mode 

    I know there's a problem with the this.close()

    Any help would be great guys!! Thanks!

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Qt4 - How to close a window?

    this is a pointer, so you need to use this->close();

Similar Threads

  1. close application window
    By seltra in forum Newbie
    Replies: 5
    Last Post: 8th October 2010, 19:12
  2. Replies: 9
    Last Post: 16th May 2010, 16:21
  3. Replies: 1
    Last Post: 19th April 2010, 07:19
  4. close window signal
    By jano_alex_es in forum Newbie
    Replies: 5
    Last Post: 22nd May 2009, 10:10
  5. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40

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.