Flow of control in execution
-
If I have two different window,say mainwindow and subwindow with different class name but both derived from QMainWindow,then how does the control work between these two window?
for example:
on click of a button in mainwindow,if I have a slot as
@void mainwindow::on_button_clicked()
{
static SubWindow *subwindow = new SubWindow(this);
subwindow->show();
subwindow->activateWindow();
subwindow->raise();
}@The respective forms are designed using Creator.Now when I close the subwindow,how will that be notified to the mainwindow?
-
Setup some signals & slots to communicate between them would be one way.
In your subwindow class, declare a signal windowClosing() and reimplement the closeEvent() like this:
@
SubWindow::closeEvent(QCloseEvent * event ) {
emit windowClosing();
QMainWindow::closeEvent(event);
}
@Then, you can connect to the signal windowClosing() from your main window.
-
I tried with the above code snippet.If I don't implement the above then also with signal and slot connection I can close my subwindow and go back to mainwindow.During this how will the control flow?Will it be in exec() loop of my mainwindow only until I close the subwindow with the respective slot?
-
What is not clear, is what you mean with "control", and how that is relevant for you. At first, it seems that you were after the program execution flow, but now, it seems to me that you're after something else.
If you really want to track execution flow of your program, then simply fire up your debugger, set a breakpoint where you want to start tracking, and step through the code line by line.
-
Hi Revu,
please, let's step back one step and look at the use case, ok?
What do you want to achive. Let's make a suggestion:- You have a main window with a button
- if the user clicks on the button, a sub main window opens
- if the sub window is closed what should happen from the users point of view?
- is the first main window usable while the second one is open? (is second one modal or non modal?)
-
Hi Revu,
Could you please explain what are you trying to achieve in general?
If you want to have several views like in Symbian C++ you check this example:
http://wiki.forum.nokia.com/index.php/Extending_QStackedWidget_for_sliding_page_animations_in_QtCheers,
Leon -
Sorry guys I posted a wrong link.
Revu, please have a look at this discussion about multiple QMainWindow at Forum Nokia: http://discussion.forum.nokia.com/forum/showthread.php?195528-Multiple-QMainWindow-but-exit-on-one-window-exits-whole-application-in-Symbian
-
@Andre:Thank you for that tip.
- You have a main window with a button - Yes
- if the user clicks on the button, a sub main window opens - Yes
- if the sub window is closed what should happen from the users point of view? - mainwindow should be visible.
- is the first main window usable while the second one is open? (is second one modal or non modal?) - I had used modal window.How can I make it non modal?At the same time track the execution control?
@Leon: When the sub window is closed,how is my mainwindow is notified?To be simple,if there is a message box on button click in my mainwindow then then how will the control be transferred from button to that message box and from message box to mainwindow?
Edit: fixed formatting; Andre
-
I think we should clarify some general points:
a modal window means you have a local event loop running while the window is open. This is done by calling exec() on a dialog. For a top level window, I think you would have to do it on your own, by locking at the implementation of QDialog::exec().
for example:
@
MyClass::foo()
{
YmDlg dlg;if(dlg.exec()) // <-- this spins a local event loop only processing events for the dialog and sub widgets. { }
}
@exec() returns when the dialog is closed.
if you have a main windows that you just show (non modal!) then the user could switch between the windows. If that is really possible depends on the system you are on and whether it supports window switching by the user (like with ALT+Tab on windows, I have no idea of your embedded system).
If switching by the user is not possible, he can only handle the visible window. when you close it he can use the now visible window.
Why do you want toi track execution control?
The user uses the visible windows. If you need modal windows on top, make them modal. A non modal windows which ensures, other windows are not used makes itself model without being it. That makes it much more complicated. -
[quote author="Revu" date="1302582827"]
@Leon: When the sub window is closed,how is my mainwindow is notified?To be simple,if there is a message box on button click in my mainwindow then then how will the control be transferred from button to that message box and from message box to mainwindow?Edit: fixed formatting; Andre
[/quote]Hi Revu,
You can handle the button click in your mainwindow and to show the message box.
If you need more help please share some of your source code.
[quote author="Gerolf" date="1302593674"]I think we should clarify some general points:
Why do you want toi track execution control?
[/quote]I am wondering why do want to track execution control, too. With Qt you have full control of all GUI components and you can show,hide,close,etc. them whenever you want.
-
Hi Leon,
Thank you for your response.I want to track the execution to know how exactly the control is getting transferred from one window to other.Is that the control of a window will be in its loop until it executes its slot?Can it be used while executing another slot of a different class?
Any idea? -
[quote author="Revu" date="1302668965"]I want to track the execution to know how exactly the control is getting transferred from one window to other.[/quote]
If you need to track the execution so badly just follow Andre's advice and use a debugger.