https://forum.qt.io/topic/49209/qfiledialog-getopenfilename-hangs-in-windows-when-using-the-native-dialog/18

QFileDialog::getOpenFileName() hangs in Windows when using the native dialog

  • Hi,

    I'm using QT 5.3.1 and I noticed that my program hangs in Windows 7 (64bit) with following arguments to the function.

    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
    "/home",
    tr("Images (*.png *.xpm *.jpg)"));

    However, if I use the option QFileDialog::DontUseNativeDialog, then
    it won't hang and will show the non-native file open dialog. I would
    prefer to use the native windows dialog so can anyone tell me if this is
    a bug or not?

    0


     
     
    18
    帖子
    10.5k
    浏览

  • Hi and welcome to devnet,

    Strange but are you aware that you are trying to open a probably non
    existent folder ? There's no /home on windows. However you can use
    QDir::home() to get the current user home path

    0


  • Yes, this is just an example syntax for this post.
    My syntax is as follows:

    fileName = QFileDialog::getOpenFileName(this,
    tr("Select file"),
    QString(),
    tr("Files (*.cvs *.svf *.txt)"));

    0


  • Do you have any network drive ?

    0

  •  

  • No I don't. I just have a C:\ drive and couple of removable drives, which are not active.
    This problem was reproduced on another PC other than mine.

    [quote author="SGaist" date="1418598787"]Do you have any network drive ?[/quote]

    0


  • Which version of Windows ?

    0

  •  

  • It is Windows 7 Professional (64bit).

    Looking at the history of Qt, I think this possibly has been a bug for some time (possibly since QT4)....
    I have seen at least 1 reported case of this sort of behaviour....

    [quote author="SGaist" date="1418678949"]Which version of Windows ?[/quote]

    0


  •  

    @SGaist

    I have just recently migrated a project I am working on to Qt5.4.1
    from Qt4.8.5, and I am having the same problem as reported by kasunf.

    A call to getOpenFileName hangs - using
    QFileDialog::DontUseNativeDialog gets it working, but I'll prefer to use
    te native windows dialog. The code snippet is shown below:

    m_imageFile = QFileDialog::getOpenFileName(this, tr("Open Image"),
    QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)"), 0,
    QFileDialog::DontUseNativeDialog); //works

    m_imageFile = QFileDialog::getOpenFileName(this, tr("Open Image"),
    QDir::homePath(), tr("Image Files (*.png *.jpg *.bmp)")); //does not
    work

    Program control does not seem to return from this function call. Has
    this issue been resolved? My system specifications are as follows:

    Windows7 64bit
    Visual Studio 2010
    Qt5.4.1_opengl

    PS: I did not have this problem with Qt4.8.5

    Thanks,

    0


  • Do you mean that when you click OK the dialog disappear but your application doesn't do anything ?

    0

  •  

  •  

    @SGaist Nope, that is not what I mean.

    The open fIle dialog does not appear at all - as though my
    application is waiting for it to appear. After investigations it turns
    out that it seems to hang in the call to

    QFileDialog::getOpenFileName(...)

    As I indicated, a call to QFileDialog::getOpenFileName(...) using the
    flag QFileDialog::DontUseNativeDialog returns from the function call,
    but the same function call without using the flag does not return.

    I will like to use it without the flag. Also, I didn't have this problem in Qt4.8.5.

    Please this is the same problem as first reported on this post. I just need to know what the status of this issue is.

    PS: I am interested in purchasing a commercial license for Qt5, but I
    need to make sure that my project works in Qt5 before going ahead with
    the purchase.

    Thanks,

    0


  • Which compiler are you using ? Just tested with VS2013 on Win 8 and no problem with the dialog.

    0


  • Facing exactly same problem on Windows 7 pro (64-bit) with Qt5.5 MSVS2010 Professional with Qt Add-in.

    0


  • win 7. 64 bit, Qt 5.5, "gcc"
    No hanging at all.
    So maybe only VS?

    Please Try with QFileDialog::DontUseCustomDirectoryIcons
    As i had case where it would take ages due to subversion overlay icons.

    1


  • I have used most of the Qt versions mentioned in this thread and
    never had a problem with using the getOpenFileName(...) member function
    with native dialogs. I have always used MinGW for Windows so maybe this
    problem is unique to Visual Studio?

    0


  •  

    @SGaist said:

    Do you have any network drive ?

    I have a problem using the functions QFileDialog::getSaveFileName and
    QFileDialog::getOpenFileName on a PC with many network drives. Could
    you please help on this? Thanks.

    0


  • Just to note this issue still exists, but does not happen on all QFileDialogs instances used in our software.

    When does it work:

    On the very first start-screen, when no other backend-threads are running, no COM connection is created etc.

    When does it not work

    Some where later in the application, when backend-threads are running, COM connection to a different application is established.

    Setup:

    Qt 5.12.3
    MSVC 2017 v15.9.7
    Windows 10 build1809

    The issue is reproducible on different computers in Debug and Release Build

    Observations

    Opening The QFileDialog leads to the following:

    The Main-UI is blocked and you can hear the windows-sound that comes,
    when the UI is blocked because a Dialog is in front and the user clicks
    somewhere on the Main-UI.

    Then

    Switching between applications (Alt-Tab) then hitting ESC, and the Main-UI is responsible again.
    This indicates, that there is an invisible Dialog on top of the main-UI.

    Opening The QFileDialog again

    Then it works!

    3


  • Same symptoms here, with QFileDialog::getExistingDirectory.

    • Before loading the COM objets, the dialog opens well, with native window.
    • After laoding COM (CoInitializeEx), calling getExistingDirectory causes the program to hang.
    • After disconnecting COM (CoUninitialize), the dialog opens well again, but with Qt window (not native) even though I did'nt specify the DontUseNativeDialog option!

    Qt 5.12.1, MSVC 2017, Windows 10

    0


  • Clearly nasty COM behaviour. I am not a Qt expert, but since your
    post and the previous one are nice and clear on the reproducibility, the
    best would be to (search first and then) report them at https://bugreports.qt.io/secure/Dashboard.jspa, see also https://wiki.qt.io/Reporting_Bugs.

    1


 
 
18
帖子
10.5k
浏览


QFileDialog::getOpenFileName() hangs的更多相关文章

  1. Qt 打开文件的默认路径 QFileDialog::getOpenFileName()

    为了说明QFileDialog::getOpenFileName()函数的用法,还是先把函数签名放在这里:   QString QFileDialog::getOpenFileName (       ...

  2. QT中用QStettings生成INI文件来记录QFileDialog::getOpenFileName上次的打开路径

    QSettings setting("./Setting.ini", QSettings::IniFormat); //QSettings能记录一些程序中的信息,下次再打开时可以读 ...

  3. QT 文件对话框(QFileDialog)

    1.选择文件(上传.打开...) QString QFileDialog::getOpenFileName( QWidget *parent = , //parent,用于指定父组件.注意,很多Qt组 ...

  4. QDialog, QFileDialog 和 QDesktopServices 的使用方法

    Qt中的QDialog类是用来生成对话框的类,QFileDialog 类是QDialog的衍生类,主要用来生成打开文件,或是打开文件目录的对话框,或者是保存文件的对话框,下面我们一一来看代码: 1. ...

  5. Obj-C 实现 QFileDialog函数

    Obj-C 实现 QFileDialog函数(getOpenFileName/getOpenFileNames/getExistingDirectory/getSaveFileName) 1.getO ...

  6. (六)QDialog,QMessageBox,QFileDialog,QColorDialog颜色,QFontDialog字体

    QDialog 对话框: 1.模态对话框: QDialog dlg(this); // 显示模态对话框 exec ,后面的不可操作 dlg.exec(); // 阻塞 2.非模态对话框: QDialo ...

  7. 六、pyqt5对话框——QInputDialog、QColorDialog、QFontDialog、QMessageBox、QFileDialog

    目录:  一.对话框综合示例 二.QDialog 三.QInputDialog 四.QMessageDialog 五.QFileDialog pyqt5的对话框有多种类型,比如输入对话框(QInput ...

  8. Qt ------ QFileDialog

    QString strFile = QFileDialog::getOpenFileName(this,QStringLiteral("选择Excel文件"),"&quo ...

  9. Qt__文件打开保存对话框(QFileDialog)

    转自豆子空间 使用QFileDialog有两种方法,一种是比较简单的使用"静态函数法",另一种是可以自定义各个细节的"构造函数法". 静态函数法 修改MainW ...

随机推荐

  1. Thinking in Java学习杂记(第7章)

    将一个方法调用同一个方法主体连接到一起就称为"绑定"(Binding).若在程序运行以前执行绑定,就叫做"早期绑定".而Java中绑定的所有方法都采用后期绑定技 ...

  2. Day19-apache

    HTTPD(俗称apache) 简介:目前来说,Linuxweb服务器主要用apache与nginx. 1.web服务器的输入/输出结构: 单线程I/O结构 多线程I/O结构 复用的I/O结构,单个线 ...

  3. 【python系统学习13】类(class)与对象(object)

    目录: 类(class)和实例 类 实例 小测试 对象(object) 属性和方法 类的创建 伪代码 示例代码 属性(attribute) 方法(method) 类的实例化 实例对象调用类属性和方法 ...

  4. CentOS 编译安装 Emacs 并配置

    Linux 中 CentOS 系列一向以稳定为目标,然而也会存在版本太旧的问题,Emacs 就是其中的一个,目前 Emacs 都发行到 25.2 了,而 CentOS 上的 Emacs 版本却还是 2 ...

  5. git使用基本步骤

    一.Git配置环境: 1.通过git init命令把某个目录变成Git可以管理的仓库: 2.生成公钥秘钥:ssh key ssh-keygen -t rsa -C "for example@ ...

  6. Redis 练习(二)

    需求: 为购物网站实现登录状态及浏览记录的维护 进入时检查 token 是否已登录 每次进入更新 token 最新进入时间 记录用户浏览的商品信息(最多 25 个) 定时检查 token 数量,如果超 ...

  7. .NET Core项目部署到Linux(Centos7)(一)前言

    目录 1.前言 2.环境和软件的准备 3.创建.NET Core API项目 4.VMware Workstation虚拟机及Centos 7安装 5.Centos 7安装.NET Core环境 6. ...

  8. JAVA中使用Date和SimpleDateFromat类表示时间

    转自:https://www.imooc.com/code/2335 仅做个人学习保存之用,侵删! 在程序开发中,经常需要处理日期和时间的相关数据,此时我们可以使用 java.util 包中的 Dat ...

  9. Jmeter常用元件

    1.测试计划:测试元件的容器,相当于一个项目名称 线程组:  2.监听器:负责收集测试结果,同时也被告知了结果显示的方式 (1)查看结果树:看具体某个请求——请求响应,结果明细 (2)聚合报告:汇总报 ...

  10. list 的sublist 隐藏 bug

    list A = new list(); list a = A.sublist(0,3); 假如对a进行增加或者删除 会 同样改变A里的值,即其实a仅仅是A的一个试图,而不是一个新的list 对象,所 ...