_ROOT Version: 6.18.4
_Platform: MacOs, Linux
_Compiler: g++
Hi,
I used to be able to create a standalone application that would throw a Canvas. I would be able to draw and redraw histograms in that canvas, which was quite powerful. It would show the histogram growing as it was filling.
The code that I used is essentially what is below. This still works, however, first it complains about multiple applications being created.
Second, I now need to call the Run() method on the application object. This used not to be necessary. I’m not interested in entering ROOTs event loop. I want to display the histogram on the canvas, and once it is modified, I want to redraw the canvas. I’m not interested in user generated events.
I have experimented with this, but it seems that whatever I do to the canvas and the histogram is only shown once Run has been called, and from that moment control has been taken from my main program.
If I remove the application object from my code, the code still works but a canvas window no longer appears.
What’s the best way of dealing with this?
sample code (originally from stackoverflow)
#include <TApplication.h>
#include <TCanvas.h>
#include <TH1D.h>
#include <thread>
#include <chrono>
#include <iostream>
int main ( int argc, char* argv[] )
{
TApplication app ("app",&argc,argv);
TCanvas canvas ("fCanvas", "fCanvas", 600, 400);
TH1D h ("h","h",10,0,10);
h.Fill(1);
h.Fill(2);
h.Fill(2);
h.Fill(2);
h.Fill(3);
h.Fill(3);
h.Draw();
canvas.Update();
canvas.Draw();
std::cout << "starting the app" << std::endl;
app.Run();
std::cout << "run was called" << std::endl;
std::this_thread::sleep_for( std::chrono::seconds(10) );
return 0;
}