Re: progressbar updates



the progress bar is only updated when the gtk main loop is run, which only happens when any functions you are running give control back to the main loop. you can force the main loop to process events (and thus update the progress bar, by doing something like this after each time you call set_fraction():

while(gtk_event_pending())
   gtk_main_iteration();

i'm not sure what the gtkmm equivalent of that is, but it's probably similar.

   -brian

Felix Natter wrote:

hi,

I want to update a progressbar while reading large XML-files.  Now when I
do this all in load_button.clicked event-handler (in the main gtk+ thread?),
then the progressbar display won't be updated when I use set_fraction.

For example, the following will not work:
void MainWindow::OnLoadXMLClicked()
{
 progressbar->set_fraction(0.2);
 sleep(1);
 progressbar->set_fraction(0.3);
 sleep(1);
 progressbar->set_fraction(0.4);
 sleep(1);
 progressbar->set_fraction(0.5);
 sleep(1);
 progressbar->set_fraction(0.6);
 sleep(1);
 progressbar->set_fraction(0.7);
 sleep(1);
 progressbar->set_fraction(0.8);
 sleep(1);
 progressbar->set_fraction(0.9);
 sleep(1);
 progressbar->set_fraction(1.0);
}
(I only see 0% and 100% but nothing in between)

Next I tried to create a thread for this task:

void MainWindow::OnLoadXMLClicked()
{

 Glib::Thread::create
(sigc::bind(sigc::mem_fun(*this, &MainWindow::loadXML), tbxFilename->get_text()), false);
}

But when I try to modify statusbar and progressbar from this
(loadXML-)thread, the gtk thread gets into trouble
(a button remains pushed, no display updates...).

I guess I need to synchronize something, but how can I do this?

thanks,




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]