独立 ROOT 应用程序不会在关闭 canvas 时终止
Standalone ROOT application doesn’t terminate upon closing a canvas
我正在制作一个独立的 ROOT 应用程序,它应该在关闭 canvas 时终止。以下是我的实验代码
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
int main(){
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas *c1 =new TCanvas("c1","Canvas Test",800,800);
c1->Connect("TCanvas", "Closed()", "TApplication",gApplication, "Terminate()");
myapp->Run();
return 0;
}
代码编译时没有任何警告。当我 运行 它时 canvas 打开。但是当我关闭 canvas 时,应用程序没有终止,终端也没有提示。有什么建议吗?
_ROOT Version: 6.20
_Platform: Ubuntu 20.04
_Compiler: g++
感谢来自 root-forum 的@bellenot 提供以下解决方案。显然,对于 ROOT 6 及以上版本,这应该使用 TRootCanvas 对象来完成。
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
int main()
{
TApplication *myapp = new TApplication("myapp", 0, 0);
TCanvas *c1 = new TCanvas("c1","Canvas Test",800,800);
TRootCanvas *rc = (TRootCanvas *)c1->GetCanvasImp();
rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
myapp->Run();
return 0;
}
我正在制作一个独立的 ROOT 应用程序,它应该在关闭 canvas 时终止。以下是我的实验代码
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
int main(){
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas *c1 =new TCanvas("c1","Canvas Test",800,800);
c1->Connect("TCanvas", "Closed()", "TApplication",gApplication, "Terminate()");
myapp->Run();
return 0;
}
代码编译时没有任何警告。当我 运行 它时 canvas 打开。但是当我关闭 canvas 时,应用程序没有终止,终端也没有提示。有什么建议吗?
_ROOT Version: 6.20
_Platform: Ubuntu 20.04
_Compiler: g++
感谢来自 root-forum 的@bellenot 提供以下解决方案。显然,对于 ROOT 6 及以上版本,这应该使用 TRootCanvas 对象来完成。
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
int main()
{
TApplication *myapp = new TApplication("myapp", 0, 0);
TCanvas *c1 = new TCanvas("c1","Canvas Test",800,800);
TRootCanvas *rc = (TRootCanvas *)c1->GetCanvasImp();
rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
myapp->Run();
return 0;
}