■
[Qt5] [QTimer] タイマー設定
1秒ごとにカウントアップした数値をコンソールに表示するプログラム。
Display counted value in console every 1000 m seconds.
◇test.h
#include <QTimer>
#include <QDebug>
QTimer *timer_HAZ2;
int count;
◇test.cpp
#include "test.h"
Test::Test(QObject *parent) : QObject(parent)
{
{
//QTimerのコンストラクタを作成
//set timer constracter
timer_test = new QTimer();
//連続したタイマを設定
//set non-single-shot timers (firing evry interval milliseconds)
timer_test->setSingleShot(false);
timer_test->setSingleShot(false);
//1000msにタイマを設定
//set the timeout interval in 1000 milliseconds
timer_test->setInterval(1000);
timer_test->setInterval(1000);
//タイマのタイプを設定
//set timer type. Precise timers try to keep millisecond accuracy. Value is 0.
timer_test->setTimerType(Qt::PreciseTimer);
timer_test->setTimerType(Qt::PreciseTimer);
//タイマをスタート
//start or restart the timer. If timer is already running, it will be stopped and restarted.
timer_test->start();
timer_test->start();
//シグナルとスロットを接続。タイマがタイムアウトする度に、スロット関数が呼びだされる。
//connect. if SIGNAL(timer_test) is timeouted, SLOT(test() method) is called.
connect(timer_test, SIGNAL(timeout()), this, SLOT(test()));
}
void MainWindow6::test()
{
count ++;
qDebug()<<count;
}
【☆Lineスタンプ販売中☆】