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 can i extend the loops limit?
Qt 6.11 is out! See what's new in the release blog

How can i extend the loops limit?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 7 Posters 4.0k Views 4 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.
  • C Offline
    C Offline
    Charlie_Hdz
    wrote on last edited by
    #6

    @Eduardo12l

    Please, give us more context if you want help... Specific questions.

    Kind Regards,
    Enrique Hernandez
    gearstech.com.mx
    chernandez@gearstech.com.mx

    1 Reply Last reply
    0
    • E Eduardo12l

      @SGaist @AlexMal I notice that when i reduce the number of lines of my algorithm i get more loops.

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

      @Eduardo12l There is no such limit! So there is nothing to extend.
      You're doing something wrong in your code.
      But nobody can help you if you do not share your code!

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

      1 Reply Last reply
      0
      • yuvaramY Offline
        yuvaramY Offline
        yuvaram
        wrote on last edited by
        #8

        @Eduardo12l
        can you provide a sample code, it could help

        Yuvaram Aligeti
        Embedded Qt Developer
        : )

        E 1 Reply Last reply
        1
        • yuvaramY yuvaram

          @Eduardo12l
          can you provide a sample code, it could help

          E Offline
          E Offline
          Eduardo12l
          wrote on last edited by Eduardo12l
          #9

          @AlexMal @Charlie_Hdz @jsulm @SGaist @yuvaram Sorry for my english. As you can at the bottom of this comment on_pushbutton_clicked() should calls criterios() 10000 times. However, it crashes close to 6500. If I erase the content of this for

           for(int i = 0; i < DiasOrdenados.size(); i++)
          

          it continues crashing close to 6500. If I comment that loop it does not crash (i mean // for(int i = 0; i < DiasOrdenados.size(); i++)). I dont understand why that for is causing a crash.

          HEADER ventanas1.h

          n = 0;
          QList<QString> DiasOrdenados << LUNES << MARTES << MIERCOLES << JUEVES << VIERNES;
          

          SOURCE ventanas1.cpp

          void Ventanas1::on_pushButton_clicked(){
              n++;
              qDebug()<<"n es"<<n;
              val = 1;
              cont = 0;
              z = true;
              if(n <= 10000){/ 
                  criterios();
              }else{
                  ui->pushButton->setStyleSheet   ("background-color: QLinearGradient(spread:pad x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0" + Vint[2][0] + ",  stop: 0.4" + Vint[2][1] + ", stop: 1.0"+ Vint[2][2]+");"
                                                  "color: #868479; "
                                                  "border-style: solid;"
                                                  "border-style: solid;"
                                                  "border-radius: 7;"
                                                  "padding: 3px;"
                                                  "padding-left: 5px;"
                                                  "padding-right: 5px;"
                                                  "border-color: #339;"
                                                  "border-width: 1px;"
                                                  "font:Bold;"
                                                  "font-family:Georgia"); //Problema potencial 1. Solo una vez permite meterle el stylesheet.
                  ui->pushButton->setText("No hay más\nopciones");
                  ui->pushButton->setEnabled(false);
              }
          }
          
          
          void Ventanas1::criterios(){  
              if(Mnh < 8){ 
                  qDebug()<<"entro";
                 umero = 0;
                  for(int i = 0; i < DiasOrdenados.size(); i++){ //In this for happends my problem
                          if(DefDias.count(DiasOrdenados.at(i)) > 0){ 
                          cont = 0;
                          val = 1;
                          while(cont < DefDias.size()){
                              if(DefDias.indexOf(DiasOrdenados.at(i),cont) != -1){ 
                                  IndCriterios << DefDias.indexOf(DiasOrdenados.at(i), cont);  
                                  cont = DefDias.indexOf(DiasOrdenados.at(i), cont)+1; 
                              }else{ 
                                  break;
                              }
                          }
                          if(IndCriterios.size() > 1){
                             for(int j = 0; j < IndCriterios.size(); j++){ 
                                 VectorAux << DefHoraF[IndCriterios[j]];
                             }
                             for(int h = 0; h < VectorAux.size(); h++){
                                   VectorAux.prepend(DefHoraI[IndCriterios[h]]); 
                                   qSort(VectorAux.begin(), VectorAux.end());  
                                    if(VectorAux.at(0) != DefHoraI.at(IndCriterios[h])){ 
                                        if(VectorAux.at(VectorAux.indexOf(DefHoraI[IndCriterios[h]])-1) - DefHoraI.at(IndCriterios[h]) + Mth < 0){ 
                                            val *= 0;
                                            numero++;
                                        }else if(VectorAux.at(VectorAux.indexOf(DefHoraI[IndCriterios[h]])-1) - DefHoraI.at(DefHoraI[IndCriterios[h]]) + Mth == Mth){ 
                                            val *= 1;
                                        }else{
                                            numero++;
                                            val *= 1;
                                        }
                                    }
                                    VectorAux.removeAt(VectorAux.indexOf(DefHoraI.at(IndCriterios[h]))); 
                             }
                          }
                          IndCriterios.clear();
                          VectorAux.clear();
                      }
          
                  }
              }
          
              on_pushButton_clicked();
          }
          

          PS: I dont know if recycling variables is causing that problem. Because I used some variables like cont and var several times in others methods.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Charlie_Hdz
            wrote on last edited by
            #10

            @Eduardo12l

            Easy, You are modifying the Vector Aux size indirectly with the functions:

            Prepend()

            And RemoveAT()

            Please modify your implementation.

            Kind Regards,
            Enrique Hernandez
            gearstech.com.mx
            chernandez@gearstech.com.mx

            E 1 Reply Last reply
            1
            • C Charlie_Hdz

              @Eduardo12l

              Easy, You are modifying the Vector Aux size indirectly with the functions:

              Prepend()

              And RemoveAT()

              Please modify your implementation.

              E Offline
              E Offline
              Eduardo12l
              wrote on last edited by Eduardo12l
              #11

              @Charlie_Hdz But it can not be the problem because if i erase all the content of

              for(int i = 0; i < DiasOrdenados.size(); i++
              

              Not only that part you said but all the content it continue failing. The difference happends when that for is present, that is the inflection point

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Charlie_Hdz
                wrote on last edited by
                #12

                First,

                Are you going to modify the DiasOrdenados, if not? Better use QVector.

                Then, your indexes are kind of confusing, please comment the end of the parenthesis.

                I Recommend you to debug, do you know how to debug?

                Thanks

                Kind Regards,
                Enrique Hernandez
                gearstech.com.mx
                chernandez@gearstech.com.mx

                E 2 Replies Last reply
                0
                • C Charlie_Hdz

                  First,

                  Are you going to modify the DiasOrdenados, if not? Better use QVector.

                  Then, your indexes are kind of confusing, please comment the end of the parenthesis.

                  I Recommend you to debug, do you know how to debug?

                  Thanks

                  E Offline
                  E Offline
                  Eduardo12l
                  wrote on last edited by Eduardo12l
                  #13

                  I have noticed that qDebug() << entro is affecting my code in some way but i dont know how. Maybe memory being affected. if i erase that qDebug() << entro it work. Wow it so rare

                  Ps: The problem happens in the moment when a function is called.

                  1 Reply Last reply
                  0
                  • C Charlie_Hdz

                    First,

                    Are you going to modify the DiasOrdenados, if not? Better use QVector.

                    Then, your indexes are kind of confusing, please comment the end of the parenthesis.

                    I Recommend you to debug, do you know how to debug?

                    Thanks

                    E Offline
                    E Offline
                    Eduardo12l
                    wrote on last edited by Eduardo12l
                    #14

                    @Charlie_Hdz i only use qdebug ¿Is there another way to check my code?
                    Ps: Whats the problem with having a loop with a condition that is dynamic? Why do you recommend use QVector instead QList?

                    E 1 Reply Last reply
                    0
                    • E Eduardo12l

                      @Charlie_Hdz i only use qdebug ¿Is there another way to check my code?
                      Ps: Whats the problem with having a loop with a condition that is dynamic? Why do you recommend use QVector instead QList?

                      E Offline
                      E Offline
                      Eeli K
                      wrote on last edited by
                      #15

                      @Eduardo12l Now, immediately, learn to debug properly. Qt Creator has the Debug button ("play" arrow with a bug) under Run button, and also Debug top level menu item.

                      Your code structure is something like

                      if 
                          for
                              if
                                  while
                                      if
                                      else break
                                      if
                                         for
                                         for 
                                             qSort(VectorAux.begin(), VectorAux.end());  
                                             if 
                                                 if 
                                                 else if
                                                       else
                      

                      First, it's difficult to read, understand or debug with any method and it's very error prone. After you have solved one problem you may run into another. You should rewrite it to be clear, easy and self-documenting. Second, you use qSort in n-th level inner loop which is probably inefficient (how many times it's executed?). Third, there might be (not necessarily) good candidates for C++ standard library algorithms like find_if which should be preferred to custom loops, both for error-freeness and readability.

                      1 Reply Last reply
                      3
                      • C Offline
                        C Offline
                        Charlie_Hdz
                        wrote on last edited by
                        #16

                        For debugging : https://www.youtube.com/watch?v=B7UsWtyhXh4

                        qDebug() is a output stream special for debugging. It doesn't represent the debugging process in its whole.

                        About QVector,I can see a lot of improvement here:

                        First, You're not modifying your QVector, so you can put it const. This is useful to avoid bugs (Nice!)

                        Second, because you're not inserting in the middle of the "Container" then you don't need QList (QList is much more inefficient that QVector)

                        Third, QVector<QString> can be easily replaced by a QStringList. Look in documentation for its advantages.

                        Then returning to the code:

                        index in this way:

                        while{
                            if{
                               }//end if
                            else{
                        
                             }//end else
                        }//end while
                        

                        Regardless what @Eeli-K said about qSort(), I think you need to practice more programming in general. Qt is facinating, all I know I learned programming in C++/Qt. Check some books, DEBUG, and enjoy.

                        ... If you finish debugging and you have a good question, please look at us.

                        Thanks

                        Kind Regards,
                        Enrique Hernandez
                        gearstech.com.mx
                        chernandez@gearstech.com.mx

                        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