简体   繁体   English

QFileDialog取消

[英]QFileDialog cancelation

I'm new to QT. 我是QT的新手。 Currently in my project I implemented QFileDialog . 目前在我的项目中我实施了QFileDialog

In my usecase : whenever user choose a text file, it executes functionA . 在我的用例中:每当用户选择文本文件时,它都会执行functionA However, I found that if I click cancel in the fileDialog, functionA will still be executed. 但是,我发现如果我在fileDialog中单击cancel,则仍会执行functionA

This is my code snipplet: 这是我的代码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. 我查看了QFileDialog文档,没有类似的内容。 Is it possible to achieve this or is there any other solution ? 有可能实现这个目标还是有其他解决方案? thanks. 谢谢。

thanks to AlexanderVX 感谢AlexanderVX

the solution is simple : 解决方案很简单:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM