Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Question regarding main() behavior

Question regarding main() behavior

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 913 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.
  • U Offline
    U Offline
    U7Development
    wrote on last edited by U7Development
    #1

    Hello!..
    I'm almost pretty new to C++, and never seen this before... so I don't know if this is expected...

    The image is self-explanatory:

    my form will show only these two lines are followed one after other...

    loginWindow.show();
    return a.exec();
    

    As you can see in the picture, if I separate the return a.exec() line, then my application will not show any window, is strange to me since it is supposed to automatically exit the if-else context after executing the loginWindow.show() line and execute the next line return a.exec()

    is this expected?.. if so, why does it behaves this way?.. Thanks.

    alt text

    Image source directly : https://imgur.com/rOv7aly

    JonBJ KroMignonK 2 Replies Last reply
    0
    • U U7Development

      Hello!..
      I'm almost pretty new to C++, and never seen this before... so I don't know if this is expected...

      The image is self-explanatory:

      my form will show only these two lines are followed one after other...

      loginWindow.show();
      return a.exec();
      

      As you can see in the picture, if I separate the return a.exec() line, then my application will not show any window, is strange to me since it is supposed to automatically exit the if-else context after executing the loginWindow.show() line and execute the next line return a.exec()

      is this expected?.. if so, why does it behaves this way?.. Thanks.

      alt text

      Image source directly : https://imgur.com/rOv7aly

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @U7Development
      I don't quite know. But whether it's the "next line" or not won't matter. You could use a debugger to step through. The window won't actually show till you hit the event loop called from a.exec(), you probably won't see it immediately after the show(), I think. Put some prints/debugs in to ensure you understand the flow of control: for example, if your CheckResourceFile() returns false then that would explain which show() is being hit and hence your claimed behaviour.

      1 Reply Last reply
      3
      • U U7Development

        Hello!..
        I'm almost pretty new to C++, and never seen this before... so I don't know if this is expected...

        The image is self-explanatory:

        my form will show only these two lines are followed one after other...

        loginWindow.show();
        return a.exec();
        

        As you can see in the picture, if I separate the return a.exec() line, then my application will not show any window, is strange to me since it is supposed to automatically exit the if-else context after executing the loginWindow.show() line and execute the next line return a.exec()

        is this expected?.. if so, why does it behaves this way?.. Thanks.

        alt text

        Image source directly : https://imgur.com/rOv7aly

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @U7Development This has nothing to do with C++, but it is the way Qt works!

        a is the QApplication, which holds the main Thread and the main event loop.

        When calling a.exec(), you are starting the main thread and all messages in the queue (e:g. signals handling) are executed by the event loop.

        Take time to read the documentation: QApplication

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        JonBJ 1 Reply Last reply
        1
        • KroMignonK KroMignon

          @U7Development This has nothing to do with C++, but it is the way Qt works!

          a is the QApplication, which holds the main Thread and the main event loop.

          When calling a.exec(), you are starting the main thread and all messages in the queue (e:g. signals handling) are executed by the event loop.

          Take time to read the documentation: QApplication

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @KroMignon
          Sorry, I don't see how your answer addresses what the OP is asking about. He is asking where loginWindow.show() must come (according to him) relative to a.exec(). Something in his claim must be wrong, if you look at his code. He claims that after executing line #33 the next line executed is not line #45 (which I would dispute and ask for proof of).

          KroMignonK 1 Reply Last reply
          1
          • JonBJ JonB

            @KroMignon
            Sorry, I don't see how your answer addresses what the OP is asking about. He is asking where loginWindow.show() must come (according to him) relative to a.exec(). Something in his claim must be wrong, if you look at his code. He claims that after executing line #33 the next line executed is not line #45 (which I would dispute and ask for proof of).

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by
            #5

            @JonB Yes, there are 2 cases for which dialog will not be shoyed:
            a. when DB is null
            b. when filesystemManager.CheckResourceFile() returns false

            That's it.
            If he wan't to have the dialog shown in every case, then show() must be called every time.

            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

            JonBJ 1 Reply Last reply
            3
            • KroMignonK KroMignon

              @JonB Yes, there are 2 cases for which dialog will not be shoyed:
              a. when DB is null
              b. when filesystemManager.CheckResourceFile() returns false

              That's it.
              If he wan't to have the dialog shown in every case, then show() must be called every time.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @KroMignon
              There I agree with you (assuming what he has commented out is still commented out, you never know with posters here!), which is what I tried to say in the first place, and encouraged him to put in trace statements or use a debugger (I simply don't think he's hitting line #33). But I didn't feel that telling him to read up on QApplication would enlighten him on this. No offence intended.

              1 Reply Last reply
              0
              • U Offline
                U Offline
                U7Development
                wrote on last edited by
                #7

                Thanks all for your replies, there was a confusion on me, I got it working now, of course the supposed error had no sense... the line 29 was returning nullptr because my file name was incorrect...

                Thanks again and my apologies..

                KillerSmathK 1 Reply Last reply
                1
                • U U7Development

                  Thanks all for your replies, there was a confusion on me, I got it working now, of course the supposed error had no sense... the line 29 was returning nullptr because my file name was incorrect...

                  Thanks again and my apologies..

                  KillerSmathK Offline
                  KillerSmathK Offline
                  KillerSmath
                  wrote on last edited by
                  #8

                  @U7Development
                  If every issues has been solved, mark this topic as Solved.

                  @Computer Science Student - Brazil
                  Web Developer and Researcher
                  “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

                  1 Reply Last reply
                  1

                  • Login

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