Cancel QFileDialog

I am new to QT. Currently in my project I have implemented QFileDialog

.

In my usecase: whenever the user selects a text file, it executes functionA

. However, I found that if I click "undo" in the Dialog file, functionA

it still gets executed.

This is my code snapshot:

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

// I want something like following :

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

      

I went through the documentation QFileDialog

and nothing like that. Is it possible to achieve this or is there another solution? thank.

+3


source to share


1 answer


thanks to AlexanderVX

the solution is simple:



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

      

+4


source







All Articles