Paul Lutus wrote:
> richard.j.dale / gmail.com wrote:
>
> >
> > Paul Lutus wrote:
> >
> >> I have not had any success updating progress bars using worker threads
> >> and the Qt GUI library, you may have a different experience with
> >> GTk:ProgressBar.
> > I can't help with the original GTK question. But in QtRuby you would
> > use a Qt::Timer that allows you to specify a ruby method as a 'slot' to
> > be called periodically. In the slot called by Qt::Timer, download a
> > single file, update the progress bar and return. That way control can
> > return to Qt's main loop, and events can be handled - otherwise the GUI
> > will just freeze while you do what might be a lengthy download of lots
> > of podcasts.
>
> Yes, tried that method. Doesn't work for a single file, the original
> objective. The reason AFAICS is the timer can't easily preempt the file
> download while it is under way, and when it can, it produces now
> information that the display routines will use to update the display, but
> only after the file download is finished.
>
> Your suggestion works for a task consisting of a series of file downloads,
> and a progress bar that indicates the total progress for all the files, and
> a timer that initiates each new file download at intervals. Yes, that
> works.
To do that you would need to create a socket, and then use a
Qt::SocketNotifier of Type Read to monitor it. The SocketNotifier emits
a signal 'activated(int)' when there is something to read on the
socket. So in the slot connected to the activated signal, you would
read from the socket, update the progress bar according to the bytes
read and return.

-- Richard