Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Flow of control in execution
QtWS25 Last Chance

Flow of control in execution

Scheduled Pinned Locked Moved Mobile and Embedded
22 Posts 4 Posters 10.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Revu
    wrote on last edited by
    #1

    Can someone explain me how does the MainWindow know that its SubWindow or any of its modal dialog is closed?
    How does the control flow from app.exec() to the modal dialog and how does it return back?

    Every fall is to raise higher than Before.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      A modal dialog that you start with exec() starts its own eventloop. That means that the call to exec only returns when that eventloop is exited.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Revu
        wrote on last edited by
        #3

        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?

        Every fall is to raise higher than Before.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          hi,

          in your case it will not be notified. Why should it?

          you created two completely independent top level windows which have no communication.
          Please explain a bit what you want to achieve and then we can perhaps help you.

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            It won't be notified explicitly, because in this case program flow just continues as usual (you are using show() instead of exec()). That is, after the function you show, control returns to the event loop of QApplication.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Revu
              wrote on last edited by
              #6

              Ok.Then how can I get control in mainwindow over my subwindow so that I get notified when the user close the window or send any event to some other window say subwindow1.

              Every fall is to raise higher than Before.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Revu
                  wrote on last edited by
                  #8

                  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?

                  Every fall is to raise higher than Before.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    Please rephrase. I don't understand what you're after.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Revu
                      wrote on last edited by
                      #10

                      sorry.In my subwindow(as in code posted in previous post) if I have a few widgets in it then will my control be w.r.t subwindow? Later how will the control be transferred to the mainwindow?

                      Every fall is to raise higher than Before.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          giesbert
                          wrote on last edited by
                          #12

                          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?)

                          Nokia Certified Qt Specialist.
                          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                          1 Reply Last reply
                          0
                          • L Offline
                            L Offline
                            leon.anavi
                            wrote on last edited by
                            #13

                            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_Qt

                            Cheers,
                            Leon

                            http://anavi.org/

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              leon.anavi
                              wrote on last edited by
                              #14

                              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

                              http://anavi.org/

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Revu
                                wrote on last edited by
                                #15

                                @Andre:Thank you for that tip.

                                @Gerolf:

                                • 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

                                Every fall is to raise higher than Before.

                                1 Reply Last reply
                                0
                                • G Offline
                                  G Offline
                                  giesbert
                                  wrote on last edited by
                                  #16

                                  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&#40;&#41;) // <-- 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.

                                  Nokia Certified Qt Specialist.
                                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                  1 Reply Last reply
                                  0
                                  • L Offline
                                    L Offline
                                    leon.anavi
                                    wrote on last edited by
                                    #17

                                    [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.

                                    http://anavi.org/

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      Revu
                                      wrote on last edited by
                                      #18

                                      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?

                                      Every fall is to raise higher than Before.

                                      1 Reply Last reply
                                      0
                                      • L Offline
                                        L Offline
                                        leon.anavi
                                        wrote on last edited by
                                        #19

                                        [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.

                                        http://anavi.org/

                                        1 Reply Last reply
                                        0
                                        • R Offline
                                          R Offline
                                          Revu
                                          wrote on last edited by
                                          #20

                                          I tried the debugger by setting the breakpoints.Thank You All.

                                          Every fall is to raise higher than Before.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved