Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Problem in While loop

Problem in While loop

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt c++embedded qtwebsocketservergridencoder
2 Posts 2 Posters 1.8k 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.
  • JerwinprabuJ Offline
    JerwinprabuJ Offline
    Jerwinprabu
    wrote on last edited by
    #1

    If I run the program while loop is working once only, but that should work continuously. Then only I can calculate grid count via server. After completed one calculation it reached to delete jread;

    void DistanceThread::run()
    {
    while (true)
     {
      QString ypositive = QString::number(ystart); //converting y start cordinate of json data to string
                                                               
       if((MainMotionThread::startofxaxis) == 0)
        {
          int distx = EncoderCount::cycleleftinterrupt+ 580;
         while (true)
          {
             if((MainMotionThread::stateofxaxis) == 0)
               {
                 if(!(EncoderCount::cycleleftinterrupt == 0))
                  {
                    if(EncoderCount::cycleleftinterrupt >= distx)
                      {
                         emit Distance_Grid_X(xstart);
                        cout<<"grid x :"<<xstart<<endl;
                         qDebug ()<< "distance grid x";
    
                        QString xpositive = QString::number(xstart);
                         data_xpositive = myid+"_me|xy|"+xpositive+"|"+ypositive;
                        emit Distance_Grid_X_Websocket(data_xpositive);
                        cout<<"grid x1 :"<<xstart<<endl;
                         xstart = xstart +1;
                         positiveflag = 1;
                          break;
                  }
             }
       }
    
     else if((MainMotionThread::stateofxaxis) == 1)
           {
              if(!(EncoderCount::cycleleftinterrupt == 0))
                 {
                    if (EncoderCount::cycleleftinterrupt >= distx)
                       {
                         emit Distance_Grid_X(xstart);
                         qDebug ()<< "distance grid x";
                         cout<<"grid x :"<<xstart<<endl;
    
                         QString xnegative = QString::number(xstart);
                         data_xnegative = myid+"_me|xy|"+xnegative+"|"+ypositive;
                         emit Distance_Grid_X_Websocket(data_xnegative);
                          cout<<"grid x2 :"<<xstart<<endl;
                          xstart = xstart - 1;
                         negativeflag = 1;
                         break;
                     }
                }
           }
                    if(this->diststop)
                    {
                        this->flagforbreak = 1;
                        break;
                    }
                }
    
            }
            emit Distance_Grid_Y(ystart); //emitting y axis value to display
            cout<<"grid y :"<<ystart<<endl;
    
            if(this->flagforbreak)//clicked and exiting main while loop
            {
                this->flagforbreak = 0;//reseting the flag for main while loop exit
                break;//exit main while loop
            }
        }
        delete jread;
    }
    

    Also, I have added Json file

    {
    "myID" : "ABC1",
    "action" : "start",
     "zone" :
        {
            "start_x" : 0,
            "start_y" : 5,
    
            "end_x" : 10,
            "end_y" : 0,
    
            "motion" :
            {
                "motion_type": "zigzag",
                "degree_of_rotation": 30,
                "rotation_direction": "clock",
                "linear_direction": "+ve"
            }
        }
    }
    
    1 Reply Last reply
    0
    • RajeeshRaveendranR Offline
      RajeeshRaveendranR Offline
      RajeeshRaveendran
      wrote on last edited by RajeeshRaveendran
      #2

      Hi,

      there are 2 possible cases:

      1. If you are sure that void DistanceThread::run() exit after first iteration then you are setting "flagforbreak" or "diststop" in between. So could you please check the slots of those signals which you are emitting? (May be the flag set from there).

      2. DistanceThread::run() is still executing but your conditions (i saw complex nested "If"s there :) ) may not meet anytime.(Hope U will debug it ensure that.

      Regards,
      Rajeesh Raveendran

      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