问题
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