[Qt-interest] How to implement a `Stop Button' ?
Michael Jackson
mike.jackson at bluequartz.net
Wed May 12 04:00:29 CEST 2010
On 5/11/10 4:11 AM, in article 4BE9113F.80904 at gmail.com, "Aaron Lewis"
wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi,
> I tried to implement a function with QPushButton , that will stop a
> task that is running.
>
> e.g A function used to search for specify strings in all of the files
> inside a directory , if the directory has a long scope , user may want
> to stop it.
>
> So far what i did is make the QPushButton checkable , and during the
> loop in the directory , everytime before i search in a file , i will
> check if the Button is `checked'.
> If it's checked , jump out of the loop immediately , and stop searching.
>
>
> The problem is , during the search function , user interface will stop
> answering me , so i won't be able to click on the button , in that case
> , i can't stop the search function.
>
> Does anyone has any ideas ?
>
> Thanks in advance !
>
>
> - --
> Best Regards,
> Aaron Lewis - PGP: 0x4A6D32A0
> FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
> irc: A4r0n on freenode
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.14 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkvpET4ACgkQvf41sEptMqBrhgCglSEad0uAtL8lWqqxz7zydiV1
> KJAAoKXt1zrKPTXEjX4jcsIjZYq0uDaL
> =ggbU
> -----END PGP SIGNATURE-----
You will need to push your searching for the strings task onto its own
thread. There are several ways to do this. The Qt Documentation goes into
detail on how to do this. Some ideas would be the following:
Hook up some signals/slots between the gui button and the task so that when
the user clicks the "Stop" button a signal is sent to the thread that marks
it for cancelation.
When the task is completed, signal the mail thread to set the GUI back to a
proper state.
Mike Jackson
More information about the Qt-interest-old
mailing list