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. QtFileDialog stocks after until subprocess finished
Forum Updated to NodeBB v4.3 + New Features

QtFileDialog stocks after until subprocess finished

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 3 Posters 1.5k Views 2 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.
  • ademmlerA ademmler

    Her is a minimal example to illustrate the issue.
    http://files.lacunasolutions.com/various/QtMinimal.zip

    Please note this might not work on windows. You may need to change the system call in the subroutine to something else.

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

    @ademmler
    Hi
    Dont use myProcess.waitForFinished(-1); as it blocks the GUI.
    Use QProcess finished signal to wait to do rest of code until it sends signal.

    void MainWindow::on_openButton_clicked()
    {
        ui->statusbar->showMessage("Open file dialog.", 0);
    
        QString imagePath = QFileDialog::getOpenFileName(
                    this,
                    tr("Open File"),
                    QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
                    tr("TIFF (*.tif *tiff);;JPEG (*.jpg *.jpeg);;PNG (*.png)" )
                    );
    
        QApplication::processEvents();
    
        doSomething(imagePath);
    
        ui->statusbar->showMessage("Waiting for subprocess to end.", 0);
    
        connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this,imagePath](){
            ui->statusbar->showMessage("Subprocess ended.", 0);
    
    
            imageObject = new QImage();
            imageObject->load(imagePath);
            image = QPixmap::fromImage(*imageObject);
    
            scene = new QGraphicsScene(this);
            pixmap = scene->addPixmap(image);
            scene->setSceneRect(image.rect());
            ui->graphicsView->setScene(scene);
    
            pixmap->setFlag(QGraphicsItem::ItemIsMovable);
        });
    
    
    }
    
    1 Reply Last reply
    2
    • ademmlerA Offline
      ademmlerA Offline
      ademmler
      wrote on last edited by
      #7

      @mrjj

      Perfect - that fixed the issue.

      How can I access stdout or error messages in this way?

      Would you tell me what do do, if I need to launch multiple sub processes and catch them separate?

      JonBJ 1 Reply Last reply
      0
      • ademmlerA ademmler

        @mrjj

        Perfect - that fixed the issue.

        How can I access stdout or error messages in this way?

        Would you tell me what do do, if I need to launch multiple sub processes and catch them separate?

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

        @ademmler

        How can I access stdout or error messages in this way?

        Search the https://doc.qt.io/qt-5/qprocess.html docs page for stdout, stderr etc.

        Would you tell me what do do, if I need to launch multiple sub processes and catch them separate?

        Just create separate QProcess instances.

        ademmlerA 1 Reply Last reply
        0
        • JonBJ JonB

          @ademmler

          How can I access stdout or error messages in this way?

          Search the https://doc.qt.io/qt-5/qprocess.html docs page for stdout, stderr etc.

          Would you tell me what do do, if I need to launch multiple sub processes and catch them separate?

          Just create separate QProcess instances.

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by
          #9

          @JonB

          thx for telling me - I read this all day ... but still it did not work d for me ...

          JonBJ 1 Reply Last reply
          0
          • ademmlerA ademmler

            @JonB

            thx for telling me - I read this all day ... but still it did not work d for me ...

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

            @ademmler
            Glancing at sample code https://gist.github.com/ynonp/8148340, this should work, and give you the idea of what is needed.

            ademmlerA 1 Reply Last reply
            1
            • JonBJ JonB

              @ademmler
              Glancing at sample code https://gist.github.com/ynonp/8148340, this should work, and give you the idea of what is needed.

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by
              #11

              @JonB

              thx for pointing me to a working example.

              1 Reply Last reply
              0
              • ademmlerA Offline
                ademmlerA Offline
                ademmler
                wrote on last edited by ademmler
                #12

                @mrjj said in QtFileDialog stocks after until subprocess finished:

                );

                connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this,imagePath](){
                    ui->statusbar->showMessage("Subprocess ended.", 0
                

                I used this and it works fine so far - the blocked dialog gets free ...
                But I am wondering how I can pause the whole application until this thread is finished.

                Using process.waitForFinish() did not work here ...

                What I want to achieve is - a free dialog, a progress bar telling me
                that something is going on and at when all processes have end the image will be displayed and progress bar is stopped.

                mrjjM 1 Reply Last reply
                0
                • ademmlerA ademmler

                  @mrjj said in QtFileDialog stocks after until subprocess finished:

                  );

                  connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), this, [this,imagePath](){
                      ui->statusbar->showMessage("Subprocess ended.", 0
                  

                  I used this and it works fine so far - the blocked dialog gets free ...
                  But I am wondering how I can pause the whole application until this thread is finished.

                  Using process.waitForFinish() did not work here ...

                  What I want to achieve is - a free dialog, a progress bar telling me
                  that something is going on and at when all processes have end the image will be displayed and progress bar is stopped.

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

                  @ademmler said in QtFileDialog stocks after until subprocess finished:

                  But I am wondering how I can pause the whole application until this thread is finished.

                  You dont pause a GUI app. That is simply wrong thinking.
                  Most of Qt classes work with signal and slot.

                  So when you do something, you simply hook up to a signal and then when the signal comes, you
                  do what you need.

                  So often you have to split the code in 2 parts.
                  The setup part
                  and the processing part where you react to the signal.

                  You cannot pause an app. It will stop drawing and turns white etc.

                  and don't use waitForFinish as it hangs the app. really not a good idea in GUI apps. ever.

                  so just use signals and slots and the app will do nothing until some signal comes and then you
                  do what you need in the slot.

                  ademmlerA 1 Reply Last reply
                  2
                  • mrjjM mrjj

                    @ademmler said in QtFileDialog stocks after until subprocess finished:

                    But I am wondering how I can pause the whole application until this thread is finished.

                    You dont pause a GUI app. That is simply wrong thinking.
                    Most of Qt classes work with signal and slot.

                    So when you do something, you simply hook up to a signal and then when the signal comes, you
                    do what you need.

                    So often you have to split the code in 2 parts.
                    The setup part
                    and the processing part where you react to the signal.

                    You cannot pause an app. It will stop drawing and turns white etc.

                    and don't use waitForFinish as it hangs the app. really not a good idea in GUI apps. ever.

                    so just use signals and slots and the app will do nothing until some signal comes and then you
                    do what you need in the slot.

                    ademmlerA Offline
                    ademmlerA Offline
                    ademmler
                    wrote on last edited by
                    #14

                    @mrjj

                    Ok - thank your for clearing this - hence I need to get into slots and signals concept ...

                    mrjjM 1 Reply Last reply
                    0
                    • ademmlerA ademmler

                      @mrjj

                      Ok - thank your for clearing this - hence I need to get into slots and signals concept ...

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

                      @ademmler
                      Yes its a must use with Qt :)
                      At least when its a GUI app.

                      1 Reply Last reply
                      0
                      • ademmlerA Offline
                        ademmlerA Offline
                        ademmler
                        wrote on last edited by
                        #16

                        Hello guys,

                        I have a conceptional question about Signals and slots which I could not find an answer.

                        1. Lets say I launch 2 processes one directly after the other.

                        2. Process A is much slower than process B.

                        3. I need to wait for Process A (and his slot subtasks) to be finished before I execute the "slot" of process B.

                        How can I achieve this?

                        mrjjM JonBJ 2 Replies Last reply
                        0
                        • ademmlerA ademmler

                          Hello guys,

                          I have a conceptional question about Signals and slots which I could not find an answer.

                          1. Lets say I launch 2 processes one directly after the other.

                          2. Process A is much slower than process B.

                          3. I need to wait for Process A (and his slot subtasks) to be finished before I execute the "slot" of process B.

                          How can I achieve this?

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

                          @ademmler
                          Hi
                          I assume you mean 2 x QProcess ?

                          You would simply hook up to A and when it says finished you
                          call the B slot.

                          Or do you mean inside B, it needs to wait for A ?

                          If you just mean inside the app, then you can just use A signal and then
                          do what you need to do as B should be finished long time ago.

                          1 Reply Last reply
                          1
                          • ademmlerA ademmler

                            Hello guys,

                            I have a conceptional question about Signals and slots which I could not find an answer.

                            1. Lets say I launch 2 processes one directly after the other.

                            2. Process A is much slower than process B.

                            3. I need to wait for Process A (and his slot subtasks) to be finished before I execute the "slot" of process B.

                            How can I achieve this?

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

                            @ademmler said in QtFileDialog stocks after until subprocess finished:

                            I need to wait for Process A (and his slot subtasks) to be finished before I execute the "slot" of process B.

                            Maybe you mean you could/should not start process B until process A is finished? Saying you don't want to execute a slot connected to process B until after those of process A seems strange.

                            1 Reply Last reply
                            1
                            • ademmlerA Offline
                              ademmlerA Offline
                              ademmler
                              wrote on last edited by
                              #19

                              To go deeper into it.

                              1. The reason is, that the time of the processes is always unknown and different. Hence I do not know how long each run of the app a process will take.

                              2. The only rule is A has to follow B

                              Isn't there any clear signal when a connect has taken place and when the related tasks are done?

                              Can I emit another Signal with in a "connection" ?

                              Regards Alexander

                              JonBJ 1 Reply Last reply
                              0
                              • ademmlerA ademmler

                                To go deeper into it.

                                1. The reason is, that the time of the processes is always unknown and different. Hence I do not know how long each run of the app a process will take.

                                2. The only rule is A has to follow B

                                Isn't there any clear signal when a connect has taken place and when the related tasks are done?

                                Can I emit another Signal with in a "connection" ?

                                Regards Alexander

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

                                @ademmler said in QtFileDialog stocks after until subprocess finished:

                                Isn't there any clear signal when a connect has taken place and when the related tasks are done?

                                What "related tasks are done"? You have seen there is a QProcess::finished signal. If you want to only start B after A has finished, use that.

                                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