Re: Yet another problem with threads :<
- From: Robert Caryl <bob fis-cal com>
- To: tboloo <azath o2 pl>
- Cc: gtkmm-list gnome org
- Subject: Re: Yet another problem with threads :<
- Date: Tue, 20 Feb 2007 11:20:57 -0600
You are making changes to the GUI directly in your thread process that
change a button widget's appearance and then changes it back one second
later w/o ever allowing the Gtk::Main::run loop to run, so naturally,
you will not see anything happen.
Bob
tboloo wrote:
> I'm trying to utilize threads in my app. Since there aren't many materials
> covering this topic this may be something trivial, but I really searched a
> lot and didn't find anything that would help me.
> This is what I've achieved so far :
> /**************** hellothread.h **************/
> class hellothread : public Gtk::Window
> {
> public:
> hellothread();
> virtual ~hellothread();
> void on_button_clicked();
> void thread_dilate();
> private:
> Gtk::Button _mButton;
> Glib::Dispatcher m_signal_finished;
> };
> /************* hellothread.cpp *****************/
> hellothread::hellothread()
> : _mButton("Hello World")
> {
> _mButton.signal_clicked().connect(sigc::mem_fun(*this,
> &hellothread::on_button_clicked));
> add(_mButton);
> _mButton.show();
> }
>
> hellothread::~hellothread()
> {
> //dtor
> }
>
> void hellothread::on_button_clicked()
> {
> Glib::Thread * thread = Glib::Thread::create(
> sigc::mem_fun(*this,&hellothread::thread_dilate), true);
> thread->join();
> }
>
> void hellothread::thread_dilate()
> {
> _mButton.set_sensitive(false);
> _mButton.set_label("Sleeping...");
> std::cout << "sleeping" << std::endl;
> sleep(1);
> std::cout << "finished sleeping" << std::endl;
> _mButton.set_label("Hello World");
> _mButton.set_sensitive(true);
> m_signal_finished.emit();
> }
> /*************** main.cpp ***************/
> int main(int argc, char* argv[])
> {
> Gtk::Main kit(argc, argv);
>
>
> hellothread thread_;
> Glib::thread_init();
> thread_.set_title( "Thread" );
> Gtk::Main::run(thread_); //Shows the window and returns when it is
> closed.
>
> return 0;
> }
> /******************************/
>
> App is working, but doesn't seem to use threads. The button's caption isn't
> altered and app just "hangs" for one second.
> If anyone would like to help me I'd be very grateful.
> Best regards,
> Bolek.
>
--
*Robert L. Caryl Jr.*
Fiscal Systems, Inc.
102 Commerce Circle
Madison, AL 35758-2706 USA
256-772-8922 ext. 108
/This e-mail message may contain privileged or confidential information. If you are not the intended recipient,
you may not disclose, use, disseminate, distribute, copy or relay this message or attachment in any way.
If you received this e-mail message in error, please return by forwarding the message and it's attachment
to the sender and then delete the message and it's attachment from your computer./
/Neither Fiscal Systems, Inc., nor its affiliates, accept any liability for any errors, omissions, corruption
or viruses in the contents of this message or any attachments that arise as a result of e-mail transmission./
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]