Connecting Progress Bar to Query

I have a question as to how to connect a progress bar to indicate the
progress of a long query to the user. I can't seem to find an example
showing how to connect the progress bar to the progress of the query. any
help is appreciated