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. How to run background process when a Dialog is showed
Qt 6.11 is out! See what's new in the release blog

How to run background process when a Dialog is showed

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 2.3k Views 3 Watching
  • 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.
  • jsulmJ jsulm

    @LeLev said in How to run background process when a Dialog is showed:

    reimplement the showEvent and run your task/code in QConcurent or QThread

    No need to use threads here as QProcess has an asynchronous API

    ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #5

    @jsulm said in How to run background process when a Dialog is showed:

    No need to use threads here as QProcess has an asynchronous API

    sorry, my bad, i thought @ManiRon was referring to some code/method by 'process'

    ManiRonM 1 Reply Last reply
    0
    • ODБOïO ODБOï

      @jsulm said in How to run background process when a Dialog is showed:

      No need to use threads here as QProcess has an asynchronous API

      sorry, my bad, i thought @ManiRon was referring to some code/method by 'process'

      ManiRonM Offline
      ManiRonM Offline
      ManiRon
      wrote on last edited by
      #6

      @LeLev said in How to run background process when a Dialog is showed:

      No need to use threads here as QProcess has an asynchronous API

      Process means in this case i meant the tasks that are done by me

      JonBJ 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #7

        Hi
        What do you want to run in the background ?
        Is it a single function ? or its some class that can process something?

        What did you already try ?

        Show some code.

        1 Reply Last reply
        0
        • ManiRonM ManiRon

          @LeLev said in How to run background process when a Dialog is showed:

          No need to use threads here as QProcess has an asynchronous API

          Process means in this case i meant the tasks that are done by me

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

          @ManiRon said in How to run background process when a Dialog is showed:

          Process means in this case i meant the tasks that are done by me

          Don't forget that if you don't want/need to have a separate thread, you can show a modal dialog but not block by using modal.show() rather than modal.exec(), so you can still do work while modal displayed.

          ManiRonM 1 Reply Last reply
          3
          • JonBJ JonB

            @ManiRon said in How to run background process when a Dialog is showed:

            Process means in this case i meant the tasks that are done by me

            Don't forget that if you don't want/need to have a separate thread, you can show a modal dialog but not block by using modal.show() rather than modal.exec(), so you can still do work while modal displayed.

            ManiRonM Offline
            ManiRonM Offline
            ManiRon
            wrote on last edited by ManiRon
            #9

            @JonB said in How to run background process when a Dialog is showed:

            while

            Actually i tried something like this

                    qDebug("Before SHow");
                    Modal.show();
                    qDebug("After SHow");
            

            Similarly for Exec

                    qDebug("Before SHow");
                    Modal.exec();
                    qDebug("After SHow");
            

            But what i observed was the first print was coming and later print was coming only when the Modal was closed

            mrjjM 1 Reply Last reply
            0
            • ManiRonM ManiRon

              @JonB said in How to run background process when a Dialog is showed:

              while

              Actually i tried something like this

                      qDebug("Before SHow");
                      Modal.show();
                      qDebug("After SHow");
              

              Similarly for Exec

                      qDebug("Before SHow");
                      Modal.exec();
                      qDebug("After SHow");
              

              But what i observed was the first print was coming and later print was coming only when the Modal was closed

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #10

              @ManiRon
              Hi
              It's important to understand that
              modal.exec() is a socalled blocking call.
              It spins an event loop in there and
              will first return once dialog is closed.

              That means it will NOT execute the next line after it dialog is gone.

              --
              modal.show() on the other hand is NOT blocking and
              will execute the next line as soon as show() has run and while the dialog is still being displayed.

              ManiRonM 2 Replies Last reply
              3
              • mrjjM mrjj

                @ManiRon
                Hi
                It's important to understand that
                modal.exec() is a socalled blocking call.
                It spins an event loop in there and
                will first return once dialog is closed.

                That means it will NOT execute the next line after it dialog is gone.

                --
                modal.show() on the other hand is NOT blocking and
                will execute the next line as soon as show() has run and while the dialog is still being displayed.

                ManiRonM Offline
                ManiRonM Offline
                ManiRon
                wrote on last edited by
                #11
                This post is deleted!
                1 Reply Last reply
                0
                • mrjjM mrjj

                  @ManiRon
                  Hi
                  It's important to understand that
                  modal.exec() is a socalled blocking call.
                  It spins an event loop in there and
                  will first return once dialog is closed.

                  That means it will NOT execute the next line after it dialog is gone.

                  --
                  modal.show() on the other hand is NOT blocking and
                  will execute the next line as soon as show() has run and while the dialog is still being displayed.

                  ManiRonM Offline
                  ManiRonM Offline
                  ManiRon
                  wrote on last edited by
                  #12

                  @mrjj I checked and it worked the way you specified

                  mrjjM 1 Reply Last reply
                  0
                  • ManiRonM ManiRon

                    @mrjj I checked and it worked the way you specified

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    @ManiRon
                    Ok that is good. Its an important difference between
                    show() and exec()

                    ManiRonM 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      @ManiRon
                      Ok that is good. Its an important difference between
                      show() and exec()

                      ManiRonM Offline
                      ManiRonM Offline
                      ManiRon
                      wrote on last edited by
                      #14

                      @mrjj said in How to run background process when a Dialog is showed:

                      show() and exec()

                      Yes thanks

                      JonBJ 1 Reply Last reply
                      0
                      • ManiRonM ManiRon

                        @mrjj said in How to run background process when a Dialog is showed:

                        show() and exec()

                        Yes thanks

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

                        @ManiRon
                        Just to be clear: it is precisely because modal.exec() does not return to the caller till after the dialog has been closed, while modal.show() lets the caller continue, (and you will later react via signal/slot to user closing dialog, documentation describes this behaviour) that I am saying you may be able to use show() so that your calling code can continue and do other processing without the need to create a separate thread. It depends on what other processing you need to do, it was just a heads-up.

                        1 Reply Last reply
                        2

                        • Login

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