Results 1 to 4 of 4

Thread: How to close first windows , and open different window but in the same application (l

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default How to close first windows , and open different window but in the same application (l

    Hello all
    Until now I was developing Qt MainWindow and always stay in this window , changing the content with QStackedWidget
    But now I need to do something like to skype , the flow is
    user open first window the login window after successful login , the window closes
    And new different window opens with the user friends , now maybe it’s the same first window
    That changed its look totally .. I don’t know.
    How I manage this in Qt ?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to close first windows , and open different window but in the same applicatio

    it should be simple, once user logs in create a new window, and close the existing one.

    Qt Code:
    1. void MainWindow::logInOk(void)
    2. {
    3. QWidget* new_window = new NewWindow("Username"); //you can have NewWindow based off QMainWindow.. any other QWidget() based class, or QWidget itself
    4.  
    5. this.close(); //to destroy
    6. //this.hide(); // to reuse it sometime later;
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to close first windows , and open different window but in the same applicatio

    The suggestion in the post above is dangerous, and should NOT be done, since after MainWindow is destroyed and you get a dangling pointer, and a leak.

    One way is to start with the main window hidden (but alive) and show a login dialog (which is NOT a child of the main window) and connect the finished() signal to MainWindow show() slot.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to close first windows , and open different window but in the same applicatio

    The suggestion in the post above is dangerous, and should NOT be done, since after MainWindow is destroyed and you get a dangling pointer, and a leak.
    Yes, I agree on this

Similar Threads

  1. Replies: 3
    Last Post: 9th March 2011, 12:52
  2. Replies: 2
    Last Post: 17th December 2010, 19:01
  3. close application window
    By seltra in forum Newbie
    Replies: 5
    Last Post: 8th October 2010, 19:12
  4. Replies: 9
    Last Post: 16th May 2010, 16:21
  5. Replies: 11
    Last Post: 15th July 2008, 13:11

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.