Hi, I’m trying to create a standalone TBrowser. That is, I could type tbrowser at the command line and the program pops up. When I click close, it closes. With this it would be possible to double-click on a ROOT file and have it automatically open in TBrowser.
This is a little more difficult than I thought though. The main problem is getting the program to close as TBrowser won’t close a TApplication by default. Here’s my code so far, trying to get it to work. Advice would be much appreciated.
// KRootBrowser.h
#include <TQObject.h>
#include <RQ_OBJECT.h>
#include <TRootBrowser.h>
class KRootBrowser : public TRootBrowser {
public:
KRootBrowser();
virtual ~KRootBrowser();
void CloseWindow();
ClassDef(KRootBrowser,0) //ROOT native GUI version of browser
};
// --------------------------------------------------------------------
// KRootBrowser.cpp
#include <TApplication.h>
#include <TGClient.h>
#include <TBrowser.h>
#include “KRootBrowser.h”
KRootBrowser::KRootBrowser()
:TRootBrowser(){}
KRootBrowser::~KRootBrowser(){}
void KRootBrowser::CloseWindow()
{
TRootBrowser::DeleteWindow();
gApplication->Terminate(0);
}
int main(int argc, char **argv)
{
TApplication app("App", &argc, argv);
KRootBrowser *kb = new KRootBrowser();
TBrowser *tb = kb->Browser();
app.Run();
return 0;
}
//=============================================
//KLinkDef.h
#pragma link C++ class KRootBrowser;
//=============================================
Compile with :
rootcint -f KDict.cpp -c KRootBrowser.h KLinkDef.h
g++ -Wall -g KRootBrowser.cpp KDict.cpp root-config --cflags --glibs
-o tbrowser