Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFileDialog cancelation

Tags:

qt

qfiledialog

I'm new to QT. Currently in my project I implemented QFileDialog.

In my usecase : whenever user choose a text file, it executes functionA. However, I found that if I click cancel in the fileDialog, functionA will still be executed.

This is my code snipplet:

QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                    "/home",
                                                 tr("Text File (*.txt"));

// I want something like following :

if(QFileDialog.isOkButtonClicked)
{
    // execute functionsA
}

I looked into QFileDialog documentation and nothing similiar. Is it possible to achieve this or is there any other solution ? thanks.

like image 908
LOK CARD Avatar asked May 26 '15 02:05

LOK CARD


1 Answers

thanks to AlexanderVX

the solution is simple :

if(!fileName.isEmpty()&& !fileName.isNull()){
// functionA
}
like image 164
LOK CARD Avatar answered Nov 15 '22 01:11

LOK CARD