PDA

View Full Version : is it possible to close a MainWindiw without the second window get closed?



saman_artorious
1st August 2012, 07:22
is it possible to close the Main application window in qt without closing the second window?

Santosh Reddy
1st August 2012, 07:50
Can you make second window also QMainWindow?

saman_artorious
3rd August 2012, 10:05
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!

amleto
3rd August 2012, 10:16
separate 'windows' do not have parents so it cannot be a child of mainwindow.


show code example.

saman_artorious
4th August 2012, 05:50
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.

ChrisW67
4th August 2012, 08:18
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.

saman_artorious
4th August 2012, 09:13
by the way can someone tell me what "Add to this user's reputation" really does?

amleto
4th August 2012, 13:27
let's say I got two MainWindows.

In what situation does that even make sense?

ChrisW67
5th August 2012, 00:35
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.

amleto
5th August 2012, 10:45
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.

ChrisW67
6th August 2012, 00:46
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.