Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top