QFileDialog cancelation

LOK CARD picture LOK CARD · May 26, 2015 · Viewed 7.1k times · Source

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.

Answer

LOK CARD picture LOK CARD · May 26, 2015

thanks to AlexanderVX

the solution is simple :

if(!fileName.isEmpty()&& !fileName.isNull()){
// functionA
}