GUI and Loop, how to break it?

Hi

I’m new in root and c++ and I don’t know if this question is already aswered, but I will try.

I have a GUI. The main idea is to show the captured data by a DAQ card, this parts is easy, I call an external program by syste() function. The result is showed in a histograms. At this moment all ok. But I want to read in a infinite loop and brake it when I want. I performed this code:

bool stop=false; while(){ if(stop) break; system("somthing"); //the call read("somthing"); //reading the colected data show("somthing"); //show the data in a histogram }

I try to change the value of the flag “stop” by a button, but the GUI is “busy” (I think, processing the loop) when I try to push it. Ifsomebody could tell me other way to stop the loop, via GUI tool, I will be very grateful.

Hi,

Just add:

In your loop, to allow Root to process GUI (and a few other) events.

Cheers, Bertrand.

[quote=“alan888”]

bool stop=false; while(){ if(stop) break; system("somthing"); //the call read("somthing"); //reading the colected data show("somthing"); //show the data in a histogram }
[/quote]Did you consider using TThread to run while(){ if(stop) { fgMutex->Lock(); fgShowit= true; fgMutex->Unlock(); break; } system("somthing"); //the call fgMutex->Lock(); read("somthing"); //reading the colected data fgMutex->Unlock(); } with the dedicated “worker thread”, using the main one to show the outcome?

void MyClass::TryShow() { if (!fgMutex->TryLock()) { if (fgShowit) { fgShowit = false; show("something"); } fgMutex->Unlock(); } TTimer::SingleShot(0,"MyClass",this,"TryShow()"); }