Results 1 to 11 of 11

Thread: is it possible to close a MainWindiw without the second window get closed?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default is it possible to close a MainWindiw without the second window get closed?

    is it possible to close the Main application window in qt without closing the second window?

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

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Can you make second window also QMainWindow?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Quote Originally Posted by Santosh Reddy View Post
    Can you make second window also QMainWindow?
    Yes, it doesn't matter. One way is to hide the first window, which doesn't seem quite wise to do that. I think whatever window, dialog ... we create n call from the first window, it automatically become its child. So, that way if I close the first, the second one gets closed as well!

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    separate 'windows' do not have parents so it cannot be a child of mainwindow.


    show code example.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Quote Originally Posted by amleto View Post
    separate 'windows' do not have parents so it cannot be a child of mainwindow.


    show code example.
    let's say I got two MainWindows. I create a member variable pointing to the second in the first window class. and new it in its constructor. this way if I close the first one, the second will be gone as well.

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Not if you don't give the second widget a parent when you create it on the heap. The application will not close until the last top level window, i.e. parentless widget, is closed.

  7. #7
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    15
    Thanked 16 Times in 15 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    by the way can someone tell me what "Add to this user's reputation" really does?

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Quote Originally Posted by saman_artorious View Post
    let's say I got two MainWindows.
    In what situation does that even make sense?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Quote Originally Posted by amleto View Post
    In what situation does that even make sense?
    It makes perfect sense if you read "Main Window" as "top-level window." You can have as many top-level windows, i.e parentless widgets, as you want in your application.

  10. #10
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    Quote Originally Posted by ChrisW67 View Post
    It makes perfect sense if you read "Main Window" as "top-level window." You can have as many top-level windows, i.e parentless widgets, as you want in your application.
    That does not answer my question since just because you can do something doesn't mean it makes sense. Moreover, the main reason for my comment was the very fact that two instances of MainWindow was suggested. For you to ignore that and relegate the comparison to two widgets also does not answer my question.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: is it possible to close a MainWindiw without the second window get closed?

    I fail to see how an application with two top-level windows, which can be any widget not just QMainWindow derivatives, is in any way non-sensical. Atypical for simple applications maybe, but not non-sensical. Picture a Qt browser application that opens and displays web pages. Besides the usual navigation menus the application window has a menu with a File > New Window option that opens a second independent window: same QApplication/process, multiple "main" windows, and the application will not close until all "main" windows are closed. This should sound familiar, most web browsers do exactly this.

Similar Threads

  1. Replies: 7
    Last Post: 23rd April 2011, 02:29
  2. Replies: 5
    Last Post: 25th July 2010, 13:41
  3. Replies: 11
    Last Post: 4th June 2008, 07:22
  4. [SOLVED] detecting when a mdi window is closed
    By elcuco in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2006, 20:50
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

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
  •  
Qt is a trademark of The Qt Company.