Hello,
i would like to use TTimer in a standalone C++ application. I copy, compile and execute the following example:
with the correction given at the end by bellenot.
However it still does “not work” on my computer, i.e.
i expected that the function DAQMainFrame::HandleTimer() is called every 100ms,
but this is not the case and when i click on “Close windows” i get a crash.
Here is the code i wrote:
#include <iostream>
#include <TApplication.h>
#include <TCanvas.h>
#include <TTimer.h>
#include <TGClient.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
using namespace std;
class DAQMainFrame : public TGMainFrame{
private:
TApplication* daqApp;
TRootEmbeddedCanvas* canvas;
TTimer* timer;
public:
DAQMainFrame(TApplication*);
virtual ~DAQMainFrame();
Bool_t HandleTimer(TTimer*);
};
DAQMainFrame::DAQMainFrame(TApplication* app) : TGMainFrame(gClient->GetRoot()){
//I get this notification, and the window opens
cout<<"DAQMainFrame constructor called\n";
daqApp = app;
canvas = new TRootEmbeddedCanvas("Ecanvas",this,800,600);
AddFrame(canvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1));
SetWindowName("TPTPC DAQ");
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
daqApp->Run();
timer = new TTimer(this, 100);//create a TTimer to call the frame's HandleTimer(TTimer*)
timer->TurnOn();
}
DAQMainFrame::~DAQMainFrame() {
//I get this notification when the window closes
cout<<"DAQMainFrame destructor called\n";
Cleanup();
timer->TurnOff();
daqApp->Terminate();
}
Bool_t DAQMainFrame::HandleTimer(TTimer*){
//I never actually get this notification
cout<<"DAQMainFrame::HandleTimer called\n";
return kTRUE;
}
int main(){
TApplication* daqApp = new TApplication("daqApp",0,0);
new DAQMainFrame(daqApp);
daqApp->Run();
return 0;
}
Here is the output of the program:
DAQMainFrame constructor called
I expected that the function DAQMainFrame::HandleTimer() is called every 100ms,
but this is not the case.
And when i click on “Close windows” i get the error:
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f5d80f1207a in __GI___waitpid (pid=11096, stat_loc=stat_loc
entry=0x7ffea575f840, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1 0x00007f5d80e8afbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2 0x00007f5d82280dd4 in TUnixSystem::StackTrace() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#3 0x00007f5d8228303c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#4 <signal handler called>
#5 0x0000000000406ac6 in DAQMainFrame::~DAQMainFrame() ()
#6 0x00007f5d81b1af7a in ?? () from /usr/lib/x86_64-linux-gnu/libGui.so.5.34
#7 0x00007f5d806077bb in Cint::G__CallFunc::Execute(void*) () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#8 0x00007f5d8224364c in TCint::CallFunc_Exec(void*, void*) const () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#9 0x00007f5d821cbb73 in TQConnection::ExecuteMethod() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#10 0x00007f5d82219ce9 in TQObject::Emit(char const*) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#11 0x00007f5d82223997 in TTimer::Notify() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#12 0x00007f5d822238c1 in TTimer::CheckTimer(TTime const&) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#13 0x00007f5d82282f79 in TUnixSystem::DispatchTimers(bool) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#14 0x00007f5d82283485 in TUnixSystem::DispatchOneEvent(bool) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#15 0x00007f5d821f3904 in TSystem::InnerLoop() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#16 0x00007f5d821f1bdf in TSystem::Run() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#17 0x00007f5d8221de1f in TApplication::Run(bool) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#18 0x0000000000406cbc in DAQMainFrame::DAQMainFrame(TApplication*) ()
#19 0x00000000004068b2 in main ()
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x0000000000406ac6 in DAQMainFrame::~DAQMainFrame() ()
#6 0x00007f5d81b1af7a in ?? () from /usr/lib/x86_64-linux-gnu/libGui.so.5.34
===========================================================
DAQMainFrame destructor called
*** Break *** segmentation violation
^CDAQMainFrame destructor called
*** Break *** segmentation violation
Thank you in advance,
Best regards,
Frédéric Faure.
_ROOT Version: 5.34
_Platform: Ubuntu 16.04
_Compiler: g++ 5.4