Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved optimizing gui and parralel processing?

    General and Desktop
    7
    15
    116
    Loading More Posts
    • 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.
    • A
      aravmadd last edited by aravmadd

      I would like to further improve my GUI based functionality.
      Right now i have working gui with various buttons and LineEdits. For example each button has its own functionality.

      void Widget::on_lineEdit_returnPressed()
      {
      
      
          QString value = "IP Address is :";
          QString value1 = ui->lineEdit->text();
          QString value2 = value + value1;
          ui->plainTextEdit->appendPlainText(value2);
      }
      
      void Widget::on_pushButton_pressed()
      {
      
      
          ui->plainTextEdit->appendHtml("<div style='color: green;'> Process Started with below Selected Parameters </div>");
          if(ui->lineEdit->text().isEmpty() || ui->lineEdit_2->text().isEmpty() || ui->lineEdit_3->text().isEmpty() || ui->lineEdit_4->text().isEmpty() )
          {
              ui->plainTextEdit->appendHtml("<div style='color: red;'> Process Failed due to some parameters missing. Please Check all the parameters needed Except in Check boxes and DropDown Menu </div>");
              ui->plainTextEdit->appendHtml("<div style='color: red;'> By Default CheckBoxes are disabled. Please Check the respective box if you want to enable </div>");
      
      
          }
          else
          {
              QString i1 = ui->lineEdit->text();
              QString i2 = ui->lineEdit_2->text();
              QString it1 = ui->lineEdit_3->text();
              QString it2 = ui->lineEdit_4->text();
              bool enaout = ui->checkBox->isChecked();
              QString res;
              if (enaout == true)
                  res = "Output Enabled";
              else
                  res = "Output Disabled";
      
              bool ra = ui->checkBox_2->isChecked();
              QString res1;
              if (ra == true)
                  res1 = "RA is  Enabled";
              else
                  res1 = "RA is Disabled";
      
              ui->plainTextEdit->appendHtml("i1:" + i1);
              ui->plainTextEdit->appendHtml("i2: " + i2);
              ui->plainTextEdit->appendHtml("it1: "+ it1);
              ui->plainTextEdit->appendHtml("it2: " + it2);
              ui->plainTextEdit->appendPlainText(res);
              ui->plainTextEdit->appendPlainText(res1);
      
      
              QString fileName = "Process.exe";
              if(QFileInfo(fileName).exists())
              {
                  QStringList arguments;
                  arguments << ui->lineEdit->text()<<ui->lineEdit_2->text();
      
                  proc = new QProcess();
      
                  proc->start(fileName,arguments);
                  if(proc->state() != QProcess::NotRunning)
                  {
                      proc->waitForFinished();
                      
                      QString result = proc->readAllStandardOutput();
                      ui->plainTextEdit->appendPlainText(result);
      
                  }
                  
                  else{
                      ui->plainTextEdit->appendPlainText("Unable to find file with this name");
                  }
                  
      
              }
      
              else
                  ui->plainTextEdit->appendHtml("<div style='color: red;'> Error While Opening Executable </div>");
      
              
          }
      }
      
      /*
      
      QProcess *proc was initialized in header and 
      proc = new Process is used in constructor.
      
      so in the above code i am directly using proc->somestuff
      
      
      */
      

      and similary for all other buttons/LineEdits.

      But however i realised that if i am using some heavy maths for example performing heavy calculations in any of the functionality it takes sometime to do that part. But my gui is unable do other tasks until output comes from one function.

      Is there a way to run all this process separately? For Example even though it takes time it should be like unable to respond install we can be able to perform other functionality by using some parrale processing/threads. I am not sure how to do this!!

      ![alt text](Capture1.PNG image url)

      This is extremely minimal version which is created now to show what I mean. For Example if i enter some information in lineEdit box then there is some corresponding function which needs to be executed when you hit enter. But until this function is completed my gui widget stays hanged, i mean i cannot enter information in 2nd lineEdit box!. SO what i would like here to do is have various parralel process, and most of time i dont have any dependecies with other boxes except with pushButton!

      FYI i checked forum but there are not many things related to this!

      I am not sure if my question title is prompt

      jsulm JonB 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @aravmadd last edited by

        @aravmadd said in optimizing gui and parralel processing?:

        proc->waitForFinished();

        This will block your GUI until process finishes. Don't do this!
        Connect a slot to https://doc.qt.io/qt-5/qprocess.html#finished signal instead. And move this code

        QString result = proc->readAllStandardOutput();
        ui->plainTextEdit->appendPlainText(result);
        

        to that slot...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        A 1 Reply Last reply Reply Quote 2
        • JonB
          JonB @aravmadd last edited by JonB

          @aravmadd said in optimizing gui and parralel processing?:

          Is there a way to run all this process separately? For Example even though it takes time it should be like unable to respond install we can be able to perform other functionality by using some parrale processing/threads. I am not sure how to do this!

          proc->waitForFinished()

          The whole point is not to use QProcess::waitForFinished. That is what blocks the UI. Use QProcess signals (like finished) to update the UI. Then the processes run asynchronously to your application.

          1 Reply Last reply Reply Quote 2
          • A
            aravmadd @jsulm last edited by

            @jsulm said in optimizing gui and parralel processing?:

            QString result = proc->readAllStandardOutput();
            ui->plainTextEdit->appendPlainText(result);

            HI Thanks for replying and giving your valuable time and suggestions. However i didnt get/ understood to do what you have said .

            I understood like this
            connect(proc, SIGNAL(finished(int , QProcess::ExitStatus )),
            this, SLOT(i am not sure which slot sorry for my stupid questiom));

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @aravmadd last edited by

              @aravmadd said in optimizing gui and parralel processing?:

              i am not sure which slot sorry for my stupid questiom

              Well, your own slot inside Widget class. Simply add a slot in Widget with same parameters as the signal.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply Reply Quote 1
              • A
                aravmadd @jsulm last edited by

                @jsulm Thanks i will give a try. Will update in forum if i can succefully implement!! Many Thanks :-)

                mrjj 1 Reply Last reply Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @aravmadd last edited by

                  @aravmadd
                  Hi
                  Just so im sure i understand.
                  You talk about doing heavy calc in app, calc, but you seem to show code running an extern process (another .exe)

                  If you mean to run some other app, all is fine but i just have to ask :)

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    sm2770s @mrjj last edited by

                    @mrjj HI! YOU are right i am also running other executable after taking all other inputs from gui. For this i am using process.

                    I am also doing some heavy math calc for example using EIgen Library and other stuff to do some moderate math. But for doing this thing it is taking sometime, and during this time my gui gets blocked because of things which already mentioned by @jsulm and @JonB

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @sm2770s last edited by JonB

                      @sm2770s
                      Well what we and you have been talking about here is QProcess, which you will solve by using signals and slots. If you have heavy Eigen calculations you need to call in the Qt process then you will have to use separate threads if you need to keep the UI responsive.

                      S 1 Reply Last reply Reply Quote 1
                      • S
                        sm2770s @JonB last edited by

                        @JonB said in optimizing gui and parralel processing?:

                        which you will solve by using signals and slots. If you have heavy Eigen calculations you need to call in the Qt process then you will have to use separate threads if you need to keep the UI responsive.

                        HI Jon! As of now i am planning to move my calculations into executable so it can be easy and my executable does that math stuff and i think that would be optimistic way.

                        But what i would like to try for now is each button/checkbox or lineedit should run without making my gui unresponsive by using different process. For time being i am trying to ignore heavy calculations and give a try.

                        Can you give some suggestion if this approach seems legit?

                        A JonB 2 Replies Last reply Reply Quote 0
                        • A
                          AnneRanch @sm2770s last edited by AnneRanch

                          @sm2770s said in optimizing gui and parralel processing?:

                          @JonB said in optimizing gui and parralel processing?:

                          which you will solve by using signals and slots. If you have heavy Eigen calculations you need to call in the Qt process then you will have to use separate threads if you need to keep the UI responsive.

                          HI Jon! As of now i am planning to move my calculations into executable so it can be easy and my executable does that math stuff and i think that would be optimistic way.

                          But what i would like to try for now is each button/checkbox or lineedit should run without making my gui unresponsive by using different process. For time being i am trying to ignore heavy calculations and give a try.

                          Can you give some suggestion if this approach seems legit?

                          I may be reading this discussion wrong, but...

                          If there is a time consuming task, it does not matter what approach you take - your GUI has to wait until the task returns valid data.
                          Perhaps "blocking (GUI) " is incorrect term to use.
                          Not sure if I agree to try to fool the user that the code is magically working "faster than a speeding bullet".
                          My approach - KISS - I prefer QConnectivity whoops - wrong word - QtConcurrent and I use it to let the user know it is actually taking time to finish the task.
                          Just my opinion.

                          S JoeCFD 2 Replies Last reply Reply Quote 0
                          • JonB
                            JonB @sm2770s last edited by

                            @sm2770s
                            So long as you do your computations out-of-process via QProcess::start() your UI will not become unresponsive, provided you use the signals/slots and not QProcess::waitFor...().

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              sm2770s @AnneRanch last edited by

                              @AnneRanch I think blocking GUI is wrong word. I mean what you understood is right!

                              1 Reply Last reply Reply Quote 0
                              • S
                                sm2770s @JonB last edited by

                                @JonB will give a look into what you mentioned . Thanks a lot again :-)

                                1 Reply Last reply Reply Quote 0
                                • JoeCFD
                                  JoeCFD @AnneRanch last edited by

                                  @AnneRanch Throw any time-consuming job into a thread or a qprocess and add a progress bar to show something is in progress. Keep GUI idle.

                                  1 Reply Last reply Reply Quote 2
                                  • First post
                                    Last post