ich möchte einen countdown starten, habe aber probleme mit der realisierung, und zwar erstelle ich ein QTime objekt und möchte darstellen, das immer eine sekunde bei timeout() abgezogen wird
Aber es ist so, das bei timeout() die aktuelle uhrzeit in dem lcd feld dargestellt wird minus einer sekunde, obwohl ich QTime mit 10 sekunden initialisiere.
Kann mir jemand sagen was ich falsch mache?
Code: Alles auswählen
class MyApp : public QMainWindow
{
Q_OBJECT
public:
explicit MyApp(QWidget *parent = 0);
~MyApp();
private:
Ui::MyApp *ui;
QTimer *my_timer;
QTime *c_time;
public slots:
void timerAction();
private slots:
void on_btnStartStop_toggled(bool checked);
};
Code: Alles auswählen
MyApp::MyApp(QWidget *parent) : QMainWindow(parent), ui(new Ui::MyApp)
{
ui->setupUi(this);
my_timer = new QTimer(this);
c_time = new QTime();
c_time->setHMS(0,0,10,0);
my_timer->setInterval(1000);
connect(my_timer, SIGNAL(timeout()), this, SLOT(timerAction()));
ui->lcdNumber->display(c_time->toString("hh:mm:ss"));
}
void MyApp::timerAction()
{
my_timer->addSecs(-1)
QTime new_time = my_timer->addSecs(c_time->elapsed()*-1);
ui->lcdNumber->display(new_time.toString("hh:mm:ss"));
/*
if(new_time == QTime(0,0,0,0))
{
qDebug("Timer abgelaufen!");
my_timer->stop();
}*/
}
void MyApp::on_btnStartStop_toggled(bool checked)
{
if(checked)
{
my_timer->start();
c_time->start();
ui->btnStartStop->setIcon(QIcon(QString::fromUtf8(":/btn/img/player_play.png")));
}
else
{
blindTimer->stop();
ui->btnStartStop->setIcon(QIcon(QString::fromUtf8(":/btn/img/player_pause.png")));
}
}
MyApp::~MyApp()
{
delete ui;
}