P
Schau dir mal folgendes für deine Form an:
updateForm.h:
#include <qtimer.h>
#include "form.h"
class UpdateForm : public Form {
Q_OBJECT
public:
UpdateForm(QWidget* parent = 0, const char* name = 0,
bool modal = FALSE, WFlags fl = 0 );
~UpdateForm();
public slots:
void showData();
void timerDone();
private:
QTimer timer;
int value;
bool running;
};
updateForm.cpp
#include <qlabel.h>
#include "updateForm.h"
UpdateForm::UpdateForm(QWidget* parent, const char* name,
bool modal, WFlags fl)
: Form( parent, name, modal, fl ),
timer(this),
value(0),
running(false)
{
connect(&timer, SIGNAL(timeout()), this, SLOT(timerDone()));
}
UpdateForm::~UpdateForm( ) { /* NOOP */ }
void UpdateForm::timerDone() {
++value;
textLabel1->setText("Timer running");
textLabel2->setText(QString("Value: %1").arg(value));
}
void UpdateForm::showData()
{
if (not running) {
running = true;
timer.start(1000);
textLabel1->setText("Timer started");
textLabel2->setText(QString("Value: %1").arg(value));
} else {
running = false;
timer.stop();
textLabel1->setText("Timer stopped");
}
}