Pressing cancel in TGFileDialog window closes application

Hello,

The following is the basic idea of what my code is at the moment.

//Constructor
Classname::Classname(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
{
  TGDockableFrame *mainMenu = new TGDockableFrame(this);
  AddFrame(mainMenu, new TGLayoutHints(kLHintsTop, 0, 0, 1, 0));
   
  TGPopupMenu *fFileMenu = new TGPopupMenu(p);
  TGMenuBar *fMenuBar = new TGMenuBar(mainMenu, 1, 1, kHorizontalFrame);
  fMenuBar->AddPopup("&File", fFileMenu, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
  mainMenu->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
   
  fFileMenu->AddEntry("Read System Configuration File", M_FILE_OPEN);
  fFileMenu->AddEntry("&Exit", M_FILE_EXIT);
  fFileMenu->Connect("Activated(Int_t)", "OPETSystemUI", this, "HandleMenu(Int_t)");
}

[code]
//HandleMenu(Int_t)
switch (id) {

case M_FILE_OPEN:
	ConstructSys();
	break;
case M_FILE_EXIT:
    CloseWindow();
    break;

}[/code]

[code]void Classname::ConstructSys()
{
static TString dir(".");
const char filetypes[] = { “All files”, "",
“ROOT files”, “.root",
“ROOT macros”, "
.C”,
“Text files”, “*.[tT][xX][tT]”,
0, 0 };
ffi.fFileTypes = filetypes;
ffi.fIniDir = StrDup(dir);
printf(“fIniDir = %s\n”, ffi.fIniDir);
new TGFileDialog(gClient->GetRoot(), this, kFDOpen, &ffi);
printf(“Open file: %s (dir: %s)\n”, ffi.fFilename, ffi.fIniDir);
dir = ffi.fIniDir;

}[/code]
Where *ffi is a protected data member of type TGFileInfo.
So first I open my GUI main frame window and then open this TGFileDialog object to open a file. However, if I press Cancel or close the dialog box, the entire application window exits and not just the dialog box. I’m not sure what I’ve done wrong. I hope what the problem is is clear. If not, please let me know. Thanks.

Hi,

I don’t see anything obviously wrong in the code you posted. Could you post a running macro reproducing your problem?

Cheers, Bertrand.

Hi Bertrand,

I figured out what the problem was. I had more code within the function ConstructSys() after opening the file dialog such that if “Cancel” is pressed, the code would try to access objects that didn’t exist so it crashed. I was able to fix it. Thank you!

Jen