Making a GUI for browsing

Hello everyone,

I am very new to ROOT. So please do forgive any obvious mistakes.

I am trying to make a gui for browsing the files on the computer. I need to select several .dat files for plotting and I thought it would easy to make a browser to navigate to the proper files and tell ROOT to plot these but I haven’t been able to find a way.

Any help would be much appreciated. :slight_smile:


Hi Aty,

I would suggest you to start by looking at the GUI tutorials in $(ROOTSYS)/tutorials/gui, and you could also write your own plugin for the ROOT browser…

Cheers, Bertrand.

Hi Bertrand,

Thanks a lot! I actually found those tutorial really helpful.

Also, I found this code on another post:

void open_file() { TGFileInfo file_info_; const char *filetypes[] = {"RAW images", "*.raw", 0, 0}; file_info_.fFileTypes = filetypes; file_info_.fIniDir = StrDup("."); new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), kFDOpen, &file_info_); if( file_info_.fFilename ) cout << "'" << file_info_.fFilename << "' selected." << endl; }

It returns the selected file name. However, I tried turning on multiple selection using

But when I now select multiple things, it does not return anything. I thought that the file name was stored in fFilename and it could be accessed this way. Does this work differently for multiple selections?

Cheers, Aty

Hi Aty,

Yes, when using multiple selection the returned TList is: file_info_.fFileNamesList

Cheers, Bertrand.

Hi Bertrand,

Right, that was silly. I actually just saw that when I looked in the documentation properly… Sorry about that.

On a totally different note, there’s been something I have been struggling with for several days and it’s been very frustrating; so frustrating that I gave up on it in fact (my account was just accepted).

I’ve been reading a .dat file with the >> operator. However, I wanted to read the file line by line (up to every ‘return’), so I thought I 'd use getline(). But for some reason, cint keeps telling me that getline(file_in, line_read) is not defined in current scope. I’m pretty sure I have all the proper header files (iostream, sstream, fstream) but it just won’t work.

I’m currently using ROOT v5.28 on Windows. Would you, by any chance, have any thoughts on that please?

Thanks a lot.

You’re welcome. And well, this code works just fine for me on Windows:

void test_getline(const char *filename = "test.txt") { ifstream infile;; if (!infile) { std::cout << "Error! Can't open " << filename << std::endl; } char line[500]; while (!infile.eof()) { infile.getline(line,500); std::cout << line << std::endl; } }
Cheers, Bertrand.

Hi Bertrand,

Thank you for that.

However, not to be picky, but I was trying to use getline() in this form: … kw=getline

since I’m storing the lines as TStrings and not char and it seems to be more direct this way. Could you please tell me if I’m missing something obvious here?

My code is something like

TString line_read;
ifstream file_in;; 
while (!file_in.eof()){
getline(file_in, line_read);
cout<< line_read << endl;

[quote=“azou191”]Hi Bertrand,

Thank you for that.

However, not to be picky, but I was trying to use getline() in this form: … kw=getline


As you can see getline accepts std::string, not TString. So you have to use std::string with std::getline.

Well, there is no getline() taking a TString as second argument… if you replace “TString line_read;” by “std::string line_read;”, it works…

[color=#00BF00]EDIT[/color]: Note you can use TString::ReadLine() directly:

TString line_read; ifstream file_in;; while (!file_in.eof()){ line_read.ReadLine(file_in); std::cout<< line_read << std::endl; }
Cheers, Bertrand.

That! That is what I needed! I can’t believe I missed that.

Thanks a lot! :slight_smile: