Project

General

Profile

RE: Wt::WTimer stops ticking ยป test26.cc

Koen Deforche, 06/21/2011 03:14 PM

 
#include <Wt/WApplication>

//---------------------------------------------------------------------------
//dialog.h
//---------------------------------------------------------------------------
#ifndef DIALOG_H
#define DIALOG_H
//---------------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#include <Wt/WContainerWidget>
namespace Wt { struct WTimer; }
//---------------------------------------------------------------------------
///Dialog handles the user interface for a Participant.
struct Dialog : public Wt::WContainerWidget
{
Dialog();
~Dialog();

private:

const boost::scoped_ptr<Wt::WTimer> m_timer;

void OnTimer();
};
//---------------------------------------------------------------------------
#endif // DIALOG_H

//---------------------------------------------------------------------------
//dialog.cpp
//---------------------------------------------------------------------------
#include <cassert>
#include <iostream>
#include <Wt/WTimer>
//---------------------------------------------------------------------------
///to prevent it being delete by Wt classes
Dialog::Dialog()
: m_timer(new Wt::WTimer)
{
assert(m_timer);

m_timer->timeout().connect(this,&Dialog::OnTimer);
m_timer->setInterval(100);
m_timer->start();
}
//---------------------------------------------------------------------------
Dialog::~Dialog()
{
assert(!"I am never called, except for the end of the program");
}

//---------------------------------------------------------------------------
void Dialog::OnTimer()
{
std::clog << "ParticipantDialog::OnTimer()\n";
}
//---------------------------------------------------------------------------

using namespace Wt;

Wt::WApplication *create_app(const Wt::WEnvironment& env)
{
WApplication *result = new WApplication(env);
result->root()->addWidget(new Dialog());
return result;
}

int main(int argc, char **argv)
{
return WRun(argc, argv, &create_app);
}
    (1-1/1)