[Interest] Qthread from QFuture?

Scott Bloom scott at towel42.com
Tue Jan 4 20:07:05 CET 2022


Is there anyway to get (if it even exists) a QThread from a QFuture/QFutureWatcher?

The main issue, and I know this going to sound horrible, I would like to kill/terminate the thread, I know its safe 😊 (famous last words)..

Here is what im doing, maybe someone has a better solution (Im sure of it).

I have a Qlineedit entry that takes a path.  Often, this path is network based, and very often over VPN, meaning its NOT always connected.

On the text changing, the window determines if the path is valid (QFileInfo::exists, isDir, isExecutable for directories, some are files).  Unfortunately, if the VPN is not connected, it can take up to 30 seconds for the OS to return “no it doesn’t exist”.  (Windows is the primary OS, but I have seen the same on Linux)

I have created a “Delayed Line Edit” class, that derives from QLineEdit, that delays the “the text is edited” by a set amount of time, to minimize the check (ie when typing the path by hand).

However, at some point this 30 second delay hits, freezes the gui and is an overall miserable experience.

What I have done, is created a simple Object “Background File Check” that has all the File Info queries.  You set the path, set what you want checked, and call “checkPath”.  This calls QtConcurrent::run on the checkPath internal function.  There is a QResultWatcher, that emits the check has finished or timed out (with a single shot timer called when checkPath is set).

99% of the time time, if its not there in 5 seconds, its dead.  So a 5000 ms timer is used.  This works great.  Except there is one problem.

If the user tries to exit the tool before all the threads have finished, the tool waits for them to close.

There is no way to interrupt the single class to the OS, its frozen in the thread (better than also freezing the GUI).  But If I could ask the watcher, give me your QThread and let me terminate it, it would fix the issue.

Any ideas?

Scott


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20220104/4b3cea6c/attachment.htm>


More information about the Interest mailing list