Home | News | Documentation | Download

TControlBar and Main Cycle dependence and Working Principle

_ROOT Version: 6.18/04
_Platform: Linux Kubuntu
_Compiler: VS Code

I have a question about TControlBar’s working principle and don’t know how to search this info appropriately.

My Assumptions/Knowledge:
I know that the main cycle is “main()” (or the name of the .C file I’m working on) and it should run only once.
However, ControlBar gives me an opportunity to call other functions when the cycle is over.

Some Example
Now, when I run the code provided below - main cycle prints 0 (the value of the “manipulate”).
Next, if I try to print manipulate again via “Button 3” it gives me error (as I understand the variable doesn’t exist any more).
However, If I press “Button2” and afterwards “Button3” - root prints the correct integer.

My questions:

  1. Have I made any mistakes in my assumptions
  2. How it is possible (How it works, where is the data stored etc) to print integer if I press “Button2” -> “Button3”

“Bonus” Question:
As I understand TControlBar and main cycle processes can run in parallel.
How can I make main cycle to be “paused”, wait for the TControlBar procedures to be over and continue afterwards

void bla()
    cout << "bla" << endl;

void main()
    int manipulate = 0;

    TControlBar *cbInit = new TControlBar("vertical", "Initialisation");

    cbInit->AddButton("button 1", "bla();", "Auto scan");
    cbInit->AddButton("Button 2", "manipulate = 2;", "Auto scan");
    cbInit->AddButton("Button 3", "cout << manipulate << endl;", "Auto scan");


    cout << manipulate << endl;

This is a scope issue, and is independent of TControlBar. If you want the manipulate variable being accessible after the main() function, then you have to move its declaration outside the function, making it global (globally accessible).

Well, I think this is not needed, but here is a way. Add those lines after cbInit->Show();:

    TRootControlBar *rcb = (TRootControlBar *)cbInit->GetControlBarImp();
1 Like

Thank you very much!!

1 Like