Fwd: Strange behavior with GTK::ProgressBar when updating outside the main thread.



Fabricio,

I got a Gtk:Window (This is my main window).  I also have a dialog box( which is still part of the main thread, and created by my main window).  In the dialog I create a new thread and register with the new thread a callback(e.g. g_FileCopyDialog::progressBarUpdate). So it looks like this:

Thread 1 - Main Gtk App (MainWindow, g_FileCopyDialog)
Thread 2 - File COPY THREAD.  This is a thread created in g_FileCopyDialog, (DirectFile::runCopyThread)

Thread 1 registers the a callback to thread 1 via: file->copy_progress.connect( sigc::mem_fun(*this, &g_FileCopyDialog::progressBarUpdate) );

Thread 1 creates the file copy thread via:   Glib::Thread *const thread = Glib::Thread::create(sigc::
mem_fun(*file, &DirectFile::runCopyThread), true );

Thread 1 does NOT join thread 2 after its created

Thread 2 will then "run"  and call g_FileCopyDialog::progressBarUpdate every time 512 bytes are copied.  This works like a charm.

The problem is that even though the g_FileCopyDialog::progressBarUpdate is being called everytime like it should,  the progress bar does not update unless I call m_pcopyprogressbar->set_fraction( .01) first with some fictionous value in THREAD 1.

I can post the entire gtk::dialog and the DirectFile class if you want me too, but i tried not to post everything to keep it simple.

Let me know,

Steve


2009/10/27 Fabrício Godoy <skarllot gmail com>

Hi, I don't understood the code flow very well.
Maybe the problem is that you need to ask to main thread to update de progressbar.
A test case should be welcome.






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