How to save a file with using `TGFileDialog`?

Hi, ROOTers

In the documentation of TGFileDialog I read:

Depending on the dlg_type it can be used for opening or saving a file […]

So I am wondering how to save a file using this widget? And what does it mean to “Save a file”. Now I am using it in the following way:

void CaenGUI::SaveHistos()
{                   
    std::cout << "Saving histograms..." << std::endl;
                    
    TGFileInfo fi;
    new TGFileDialog( gClient->GetRoot(), fMainFrame, kFDSave, &fi );
                    
    TFile* file = new TFile( fi.fFilename, "RECREATE" );
    if( file->IsZombie() )                                                                        
    {                   
        new TGMsgBox( gClient->GetRoot(), fMainFrame, "ERROR", "Cannot save data", kMBIconExclamat     ion, kMBOk );
        delete file;
        return;
    }   
    if( fMaxHist != nullptr ) { fMaxHist->Write(); }
    if( fIntegralHist != nullptr ) { fIntegralHist->Write(); }
                    
    file->Close();
    delete file;                                                                                       
}

And I am not sure if I am doing it correctly.


ROOT Version: 6.04/00
Platform: SL7
Compiler: gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)


Something like this:

const char *filetypes[] = {
   "ROOT files", "*.root",
   "All files",  "*",
   0,            0
};

...

   TGFileInfo fi;
   fi.fFileTypes = filetypes;
   fi.fIniDir    = StrDup(".");
   new TGFileDialog( gClient->GetRoot(), fMainFrame, kFDSave, &fi );
   if (fi.fFilename) {
      TFile* file = new TFile( fi.fFilename, "RECREATE" );
      ...
   }

OK. It means I understood the words “save a file” correctly. Thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.