Hi,

I am using QFilDialog::getOpenFilename() to get the file name chosen by the user. It is working fine for me. But the issue is when the user chose to press the "Cancel" button instead of "Open". When I press the Cancel button I am closing the dialog with close signal. But program get struck after closing the window. I am confused of writing the logic between "open" and cancel" button. My code is

Qt Code:
  1. QString Directoryfinder::getFilename()
  2. {
  3. QFileDialog *dialog;
  4. QString filepath = dialog->getOpenFileName(this, tr("Open File"),"/home",tr("Text files(*.txt)"));
  5. if(filepath.isNull())
  6. connect(dialog,SIGNAL(rejected()),dialog,SLOT(close()));
  7.  
  8. return filepath;
  9. }
To copy to clipboard, switch view to plain text mode 

Can anyone please guide me with the logic.

Thank You,

baluk