QDir hangs on accessing CIFS remote folder when disconnected

梦想与她 提交于 2020-01-03 02:23:10

问题


I'm using Qt 4.7 on CentOS 6.0. I have a remote share folder mounted with CIFS:

mount -t cifs //PC128/mnt /media/net -o username=user,password=pwd,rw,noexec,soft,uid=user,gid=user

When remote folder is somehow incorrectly disconnected (e.g. the network cable is pulled out) my application hangs because of QDir locks on attempt to touch the folder (e.g. QDir::exists call). After ~90 seconds it unlocks and returns false.

It looks right - the timeout to


回答1:


QDir uses synchronous file API. When underlying file system freezes, it freezes too. There are 2 options to avoid GUI freeze:

1. Move file operations to a separate thread. Use signal/slot connection to request the thread to perform QDir::exists call and to pass the result back into the GUI thread. If the filesystem freezes, only the background thread will be frozen. GUI will still operate.

2. Use a library that uses asynchronous file API. Any request made by this library will return control flow to your app immediately. The result will be passed to the callback function. See this question for available options.



来源:https://stackoverflow.com/questions/17929294/qdir-hangs-on-accessing-cifs-remote-folder-when-disconnected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!