Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. My gui is taking too much time to plot and during plot time its being freeze...

My gui is taking too much time to plot and during plot time its being freeze...

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 4 Posters 1.9k 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.
  • P Offline
    P Offline
    prabhatjha
    wrote on last edited by
    #1

    i made a gui in which i am using multiple loops and i am using vector ......every thing fine but its taking too much time to plot and during plot time gui is being freezed......please help me to come out from this hell.......thanks

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prabhatjha
      wrote on last edited by
      #2

      This is my code.......for plot

      double Nharmonic = 6;
      double Shipspeed = 27.6 ;
      double BladeThick = 0.2;
      double BladeLen = 5;
      double KinematicVis = pow(10,-6.0);
      double ENoPiston = 4;
      double Fbroad = 0;

      double Fpeak = 100 + Shipspeed*10 ;
      double Rnl1hz = 60 + Shipspeed*2 ;
      
      double ShaftFreq = floor(ui->No_of_Shaft_rpm_lineEdit_7->text().toDouble()/60);
      double BladeFreq = ShaftFreq*ui->No_of_Propeller_Blades_lineEdit_8->text().toDouble();
      double EngineFreq = ShaftFreq*ui->GearBox_Ratio__lineEdit_7->text().toDouble();
      
      double temp = 0;
      double Coefficientsummation = 0;
      double amp =0;
      double TempRandom = 0.0;
      
      
      //Data for plot
      QVector<double> XShaftSignal(T*fs ,0);
      QVector<double> XBladeSignal(T*fs ,0);
      QVector<double> XPropeller(T*fs ,0);
      QVector<double> XCavitation(T*fs ,0);
      QVector<double> XFlow;
      QVector<double> XCylinFiring(T*fs ,0);
      QVector<double> XCrankshaft(T*fs ,0);
      QVector<double> XPistonslap(T*fs ,0);
      QVector<double> XEngineValve(T*fs ,0);
      QVector<double> XPistonRing(T*fs ,0);
      QVector<double> XEngine(T*fs ,0);
      QVector<double> XGearBox;
      QVector<double> Xtotal(T*fs ,0);
      QVector<double> XBroadband(T*fs ,0);
      
      
      
      for(int j = 0;  j < T*fs; j = j + 1)
      {
          t.append(j/fs);
          f.append((j*fs)/(fs*T));
          
          
      }
      
      
      for (int i = 0 ; i < Nharmonic; i++)
      {
          temp = Rnl1hz + 8 - 2*(i+1) ;
          
          for (int j = 0; j < t.count(); j++)
          {
              XShaftSignal.replace(j, XShaftSignal.at(j) + pow(10,(temp/20))*cos(2*pi*t.at(j)*ui->No_of_Propellers_lineEdit_6->text().toDouble()*ShaftFreq*(i+1)));
              
              
          }
          
          Coefficientsummation = Coefficientsummation + pow(10,(temp/20)) ;
          
      }
      
      
      
      
      
      for (int i = 0; i <  Nharmonic; i++)
      {
          temp = Rnl1hz + 17 - 2*(i+1) ;
          for (int j = 0; j < t.count(); j++)
          {
              XBladeSignal.replace(j,XBladeSignal.at(j) + pow(10,(temp/20))*cos(2*pi*t.at(j)*ui->No_of_Propellers_lineEdit_6->text().toDouble()*BladeFreq*(i+1)));
          }
          Coefficientsummation = Coefficientsummation + pow(10,(temp/20)) ;
          
      }
      
      
      for (int j = 0; j < t.count(); j++)
      {
          XPropeller.replace(j,XShaftSignal.at(j) + XBladeSignal.at(j));
          
      }
      
      //////////// Cavitation Noise ///////////////////////
      
      
      double  Flow_Vel = 4*Shipspeed*0.5144;
      double RenolNo = Flow_Vel*BladeLen/KinematicVis ;
      
      double CorrectedThick = BladeThick + 0.0297 * BladeLen/pow(RenolNo,(0.2));
      double Tipspeed = (2*pi*BladeLen*ui->No_of_Shaft_rpm_lineEdit_7->text().toDouble())/60;
      double Ls = 175 + 60*log10(Tipspeed/25) + log10(ui->No_of_Propeller_Blades_lineEdit_8->text().toDouble()/4);
      
      
      if (ui->checkBox_Cavitation->isChecked())
      {
          for (int i = 99 ; i < 8000; i++)
          {
              temp = Ls + 20*(1 - log10(i+1));
              
              
              for (int j = 0; j < t.count(); j++)
              {
                  XCavitation.replace(j,XCavitation.at(j) + pow(10,(temp/40))*cos(2*pi*t.at(j)*(i+1)));
              }
              Coefficientsummation = Coefficientsummation + pow(10,(temp*0.025)) ;
              
              
          }
          
          
      }
      
      
      /////////////// Flow Induced Noise ///////////////////////////
      
      if (ui->checkBox_Flow->isChecked())
      {
          double Fv = 0.18*Flow_Vel/CorrectedThick ;
          if(Shipspeed > 10)
          {
              temp = 1.5 * (Shipspeed - 10);
              for (int j = 0; j < t.count(); j++)
              {
                  XFlow.append(pow(10,(temp/20))*cos(2*pi*t.at(j)*Fv));
              }
              Coefficientsummation = Coefficientsummation + pow(10,(temp*0.05)) ;
          }
          else
          {
              XFlow.append(0);
          }
          
          
      }
      
      
      else
      {
          for (int j = 0; j < t.count(); j++)
          {
              XFlow.append(0);
          }
          
      }
      
      
      
      for (int i = 0; i< Nharmonic;i++)
      {
          
          amp = pow(10,((Rnl1hz + 13.5 - 1.5*(i+1))/20));
          
          for (int j = 0; j < t.count(); j++)
          {
              XCylinFiring.replace(j, XCylinFiring.at(j) + (amp/3)*cos(2*pi*t.at(j)*(i+1)*EngineFreq*(ENoPiston/2)));
              XCrankshaft.replace(j, XCrankshaft.at(j) + (amp/4)*cos(2*pi*t.at(j)*(i+1)*EngineFreq));
              XPistonslap.replace(j, XPistonslap.at(j) + amp*cos(2*pi*t.at(j)*(i+1)*EngineFreq*ENoPiston));
              XEngineValve.replace(j, XEngineValve.at(j) + (amp/2)*cos(2*pi*t.at(j)*(i+1)*EngineFreq*ENoPiston*ui->No_of_Values_per_Piston_lineEdit->text().toDouble()));
              XPistonRing.replace(j,XPistonRing.at(j) + (amp/5)*cos(2*pi*t.at(j)*(i+1)*EngineFreq*ENoPiston*ui->No_of_Rings_per_Piston_lineEdit_5->text().toDouble()));
              
          }
          Coefficientsummation = Coefficientsummation + (amp/3);
          
      }
      
      for (int i = 0; i< Nharmonic;i++)
      {
          amp = pow(10,((Rnl1hz + 13.5 - 1.5*(i+1))/20));
          
          Coefficientsummation = Coefficientsummation + (amp/4);
      }
      
      
      for (int i = 0; i< Nharmonic;i++)
      {
          amp = pow(10,((Rnl1hz + 13.5 - 1.5*(i+1))/20));
          
          Coefficientsummation = Coefficientsummation + (amp);
      }
      
      1 Reply Last reply
      0
      • O Offline
        O Offline
        onek24
        wrote on last edited by
        #3

        Please add the @ tag to your code, one before and one after your code.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You seem to be using lots of loops in there.

          You should consider offloading the math part to a different thread or depending on your calculation, use QtConcurrent.

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Offline
            P Offline
            prabhatjha
            wrote on last edited by
            #5

            @ double Nharmonic = 6; double Shipspeed = 27.6 ;
            double BladeThick = 0.2;
            double BladeLen = 5;
            double KinematicVis = pow(10,-6.0);
            double ENoPiston = 4;
            double Fbroad = 0;
            double Fpeak = 100 + Shipspeed10 ;
            double Rnl1hz = 60 + Shipspeed
            2 ; double ShaftFreq = floor(ui->No_of_Shaft_rpm_lineEdit_7->text().toDouble()/60); double BladeFreq = ShaftFrequi->No_of_Propeller_Blades_lineEdit_8->text().toDouble(); double EngineFreq = ShaftFrequi->GearBox_Ratio__lineEdit_7->text().toDouble(); double temp = 0; double Coefficientsummation = 0; double amp =0; double TempRandom = 0.0;

            QVector<double> XShaftSignal(Tfs ,0);
            QVector<double> XBladeSignal(T
            fs ,0);
            QVector<double> XPropeller(Tfs ,0);
            QVector<double> XCavitation(T
            fs ,0);
            QVector<double> XFlow;
            QVector<double> XCylinFiring(Tfs ,0);
            QVector<double> XCrankshaft(T
            fs ,0); QVector<double> XPistonslap(Tfs ,0); QVector<double> XEngineValve(Tfs ,0); QVector<double> XPistonRing(Tfs ,0); QVector<double> XEngine(Tfs ,0); QVector<double> XGearBox; QVector<double> Xtotal(Tfs ,0);
            QVector<double> XBroadband(T
            fs ,0);
            for(int j = 0; j < Tfs; j = j + 1)
            {
            t.append(j/fs);
            f.append((j
            fs)/(fsT)); }
            for (int i = 0 ; i < Nharmonic; i++) {
            temp = Rnl1hz + 8 – 2
            (i+1) ; for (int j = 0; j < t.count(); j++) {
            XShaftSignal.replace(j, XShaftSignal.at(j) + pow(10,(temp/20))cos(2pit.at(j)ui->No_of_Propellers_lineEdit_6->text().toDouble()ShaftFreq(i+1))); } Coefficientsummation = Coefficientsummation + pow(10,(temp/20)) ; } for (int i = 0; i < Nharmonic; i++) { temp = Rnl1hz + 17 – 2(i+1) ;
            for (int j = 0; j < t.count(); j++) {
            XBladeSignal.replace(j,XBladeSignal.at(j) + pow(10,(temp/20))cos(2pi
            t.at(j)ui->No_of_Propellers_lineEdit_6->text().toDouble()BladeFreq(i+1))); }
            Coefficientsummation = Coefficientsummation + pow(10,(temp/20)) ; } for (int j = 0; j < t.count(); j++) { XPropeller.replace(j,XShaftSignal.at(j) + XBladeSignal.at(j)); } double Flow_Vel = 4
            Shipspeed0.5144; double RenolNo = Flow_VelBladeLen/KinematicVis ; double CorrectedThick = BladeThick + 0.0297 * BladeLen/pow(RenolNo,(0.2)); double Tipspeed = (2piBladeLenui->No_of_Shaft_rpm_lineEdit_7->text().toDouble())/60; double Ls = 175 + 60log10(Tipspeed/25) + log10(ui->No_of_Propeller_Blades_lineEdit_8->text().toDouble()/4); if (ui->checkBox_Cavitation->isChecked())
            { for (int i = 99 ; i < 8000; i++) {
            temp = Ls + 20*(1 – log10(i+1)); for (int j = 0; j < t.count(); j++)
            { XCavitation.replace(j,XCavitation.at(j) + pow(10,(temp/40))cos(2pit.at(j)(i+1))); }
            Coefficientsummation = Coefficientsummation + pow(10,(temp0.025)) ; } }
            if (ui->checkBox_Flow->isChecked())
            { double Fv = 0.18
            Flow_Vel/CorrectedThick ; if(Shipspeed > 10) { temp = 1.5 * (Shipspeed – 10); for (int j = 0; j < t.count(); j++) { XFlow.append(pow(10,(temp/20))cos(2pit.at(j)Fv)); } Coefficientsummation = Coefficientsummation + pow(10,(temp0.05)) ; } else { XFlow.append(0); } } else { for (int j = 0; j < t.count(); j++) { XFlow.append(0); } } for (int i = 0; i< Nharmonic;i++) { amp = pow(10,((Rnl1hz + 13.5 – 1.5(i+1))/20)); for (int j = 0; j < t.count(); j++) { XCylinFiring.replace(j, XCylinFiring.at(j) + (amp/3)cos(2pit.at(j)(i+1)EngineFreq(ENoPiston/2))); XCrankshaft.replace(j, XCrankshaft.at(j) + (amp/4)cos(2pit.at(j)(i+1)EngineFreq)); XPistonslap.replace(j, XPistonslap.at(j) + ampcos(2pit.at(j)(i+1)EngineFreqENoPiston)); XEngineValve.replace(j, XEngineValve.at(j) + (amp/2)cos(2pit.at(j)(i+1)EngineFreqENoPistonui->No_of_Values_per_Piston_lineEdit->text().toDouble())); XPistonRing.replace(j,XPistonRing.at(j) + (amp/5)cos(2pit.at(j)(i+1)EngineFreqENoPistonui->No_of_Rings_per_Piston_lineEdit_5->text().toDouble())); } Coefficientsummation = Coefficientsummation + (amp/3); } for (int i = 0; i< Nharmonic;i++) { amp = pow(10,((Rnl1hz + 13.5 – 1.5(i+1))/20)); Coefficientsummation = Coefficientsummation + (amp/4); } for (int i = 0; i< Nharmonic;i++) { amp = pow(10,((Rnl1hz + 13.5 – 1.5*(i+1))/20)); Coefficientsummation = Coefficientsummation + (amp); } @

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              No need to repost, just update the post containing the code.

              You will also need to redo the formatting within the tags to make the code readable

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                prabhatjha
                wrote on last edited by
                #7

                actuall there is a loop for xcavitation which taj=ke too much time because its size is too much large....can u give me some suggesion to come out from this problem..

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Like I suggested before, offload the heavy math in a thread (using e.g. a worker object), send the results back to your plot widget when it's done and then update the plot

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #9

                    Here's an example for doing heavy maths in another thread to stop the GUI from freezing: http://qt-project.org/doc/qt-5/qtcore-mandelbrot-example.html

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0

                    • Login

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