Project

General

Profile

RE: Can new created thread emit signals to Wt thread usin... » GUIApplication.cpp

ruliang ge, 05/07/2010 06:46 AM

 
#include "GUIApplication.h"
#include "DataSource.h"
#include <stdio.h>
#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>


GUIApplication::GUIApplication(const WEnvironment& env)
: WApplication(env),
app_(WApplication::instance())
{
setTitle("GUI");
counterTest_ = new WText("GUI Test",root());
eventConnection_ =
DataSource::getInstance()->sourceEvent().connect(SLOT(this,
GUIApplication::showCounter));
}

/*
* Signal process function.
* Using Server Push.
*/
void GUIApplication::showCounter(int arg_number){
WApplication::UpdateLock lock = app_->getUpdateLock();

app_->attachThread();
char number[4] = {0};
sprintf(number,"%d",arg_number);
counterTest_->setText("");
counterTest_->setText(number);
app_->triggerUpdate();
}


WApplication *createApplication(const WEnvironment& env)
{
return new GUIApplication(env);
}

int main(int argc, char **argv)
{
boost::thread(boost::bind(&DataSource::Start, DataSource::getInstance()));
return WRun(argc, argv, &createApplication);
}
(2-2/4)