Problem in While loop
Unsolved
Mobile and Embedded
-
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" } } }
-
Hi,
there are 2 possible cases:
-
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).
-
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 -