PDA

View Full Version : QFileDilaog:: cancel button



kulsekarr
20th March 2015, 13:08
Hi all,

I am able to open a fileDialog and get the file name (for example:) before selecting the filename, if I click the cancel button or close the fileDialog the messagebox is displayed which is in the code

But the message box should be displayed after the open button is clicked, right now it is displayed if i click cancel button or close the fileDilaog. anyone can give some suggestions.
I have attached the code




if (!QFile::exists(f+func))
{
fileName = QFileDialog::getOpenFileName(this,tr("Open CSV File"), "", tr("CSV Files (*.csv)"));

QFile::copy(fileName, f+func);

QMessageBox::information(this,tr("Batgenerator"),tr("Import table succeed"));--------> MESSAGE box to be displayed after clicking open
m_buttonimporttable->show();

if((m_listCSVmajCSV->selectedItems().count()==1))
{
m_buttonAddVarToFile->show();
m_buttonMajCSV->show();
m_checkBkMajCSV->show();
}
}


Thanks in Advance!

anda_skoa
20th March 2015, 13:30
getOpenFileName() returns an empty string when cancel is clicked or the dialog is closed, so check fileName.isEmpty()

Cheers,
_

Lesiok
20th March 2015, 13:32
Simply test if fileName is not empty
if( !fileName.isEmpty() )
{
QFile::copy....
}