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. optimizing gui and parralel processing?
QtWS25 Last Chance

optimizing gui and parralel processing?

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 7 Posters 567 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.
  • A Offline
    A Offline
    aravmadd
    wrote on last edited by aravmadd
    #1

    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

    jsulmJ JonBJ 2 Replies Last reply
    0
    • A 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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      2
      • A 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

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @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
        2
        • jsulmJ jsulm

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

          A Offline
          A Offline
          aravmadd
          wrote on last edited by
          #4

          @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));

          jsulmJ 1 Reply Last reply
          0
          • A aravmadd

            @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));

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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
            1
            • jsulmJ jsulm

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

              A Offline
              A Offline
              aravmadd
              wrote on last edited by
              #6

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

              mrjjM 1 Reply Last reply
              0
              • A aravmadd

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

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

                @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
                0
                • mrjjM mrjj

                  @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 Offline
                  S Offline
                  sm2770s
                  wrote on last edited by
                  #8

                  @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

                  JonBJ 1 Reply Last reply
                  0
                  • S sm2770s

                    @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

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #9

                    @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
                    1
                    • JonBJ 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 Offline
                      S Offline
                      sm2770s
                      wrote on last edited by
                      #10

                      @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 JonBJ 2 Replies Last reply
                      0
                      • S sm2770s

                        @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 Offline
                        A Offline
                        Anonymous_Banned275
                        wrote on last edited by Anonymous_Banned275
                        #11

                        @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 JoeCFDJ 2 Replies Last reply
                        0
                        • S sm2770s

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

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by
                          #12

                          @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
                          0
                          • A Anonymous_Banned275

                            @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 Offline
                            S Offline
                            sm2770s
                            wrote on last edited by
                            #13

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

                            1 Reply Last reply
                            0
                            • JonBJ JonB

                              @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 Offline
                              S Offline
                              sm2770s
                              wrote on last edited by
                              #14

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

                              1 Reply Last reply
                              0
                              • A Anonymous_Banned275

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

                                JoeCFDJ Offline
                                JoeCFDJ Offline
                                JoeCFD
                                wrote on last edited by
                                #15

                                @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
                                2

                                • Login

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