[gtkmm] Threads and signals



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Any reason why the following doesn't work?
On my maching with gtkmm-2.2.7

It will toggle the checkbutton the first time only and never update the
progress bar.

If I remove the signal_stupid_ code the progress bar works fine?

The fraction and state messages show up on the console, so the signals
are recieved but the gui never gets updated.

#include <iostream>
#include <iomanip>
#include <gtkmm.h>
#include <sigc++/class_slot.h>

using namespace std;

class MainWindow : public Gtk::Window
{
public :
~  MainWindow();
~  ~MainWindow();

protected :

private :
~  Gtk::VBox m_box;
~  Gtk::ProgressBar m_bar;
~  Gtk::Button b_start;
~  Gtk::Button b_quit;
~  Gtk::CheckButton b_done;
~  SigC::Signal0<void> signal_increment_;
~  SigC::Signal0<void> signal_stupid_;
~  int increment_value;
~  const int increment_max;

~  void signal_increment()
~  {
~    double fraction = (double)increment_value / (double)increment_max;
~    cout << "fraction = " << fraction << endl;
~    m_bar.set_fraction (std::min (fraction, 1.0));
~  }
~  void signal_stupid()
~  {
~    bool state = !b_done.get_active();
~    cout << "state = " << state << endl;
~    b_done.set_active (state);
~  }
~  void start_clicked()
~  {
~    Glib::Thread::create (SigC::slot_class (*this,
~                                            &MainWindow::thread_increment),
~                          false);
~  }
~  void quit_clicked()
~  {
~    hide();
~  }
~  void thread_increment()
~  {
~    for (increment_value = 0; increment_value <= increment_max;
~         increment_value++)
~      {
~        Glib::usleep (1000000);
~        signal_increment_();
~        signal_stupid_();
~      }
~  }
};

MainWindow::MainWindow()
~  : b_quit(Gtk::Stock::QUIT), b_start("start"), b_done ("done"),
~    increment_max(10), increment_value (0)
{
~  set_title ("Progress bar");
~  //  set_default_size (200, 200);

~  add (m_box);
~  m_box.pack_start (m_bar);
~  m_box.pack_start (b_done);
~  m_box.pack_start (b_start);
~  b_start.signal_clicked().connect (SigC::slot (*this,
~                                    &MainWindow::start_clicked));
~  m_box.pack_start (b_quit);
~  b_quit.signal_clicked().connect (SigC::slot (*this,
~                                    &MainWindow::quit_clicked));
~  signal_increment_.connect (SigC::slot (*this,
~                                    &MainWindow::signal_increment));
~  signal_stupid_.connect (SigC::slot (*this,
~                                    &MainWindow::signal_stupid));
~  show_all_children();
}

MainWindow::~MainWindow()
{
}

int
main (int argc, char *argv[])
{
~  Glib::thread_init();
~  Gtk::Main kit (argc, argv);
~  MainWindow window;
~  Gtk::Main::run (window);
~  return 0;
}

- --
*************************************************
*   Greg Rogers		Cray Inc.		*
*   grogers cray com	(715)726-4631		*
*************************************************
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/Xjlds3ZHWtAE+l4RAn/6AJsHrK2yv7B75qvt8ig1Xo9OK2FcygCgj74x
/z66gODsWmilpZzKfg4RBus=
=SP7N
-----END PGP SIGNATURE-----




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