반응형
참고 : doc.qt.io/qt-5/qtimer.html#QTimer
1. Class 추가
메뉴에서 Class 를 추가한다.
4. Timer.h
Timer Class 구조체 생성
#ifndef TIMER_H
#define TIMER_H
#include <QTimer>
class Timer : public QObject
{
Q_OBJECT
public:
Timer();
QTimer *mytimer;
public slots:
void MyTimerSlot();
};
#endif // TIMER_H
3. Timer.cpp 코딩
#include "timer.h"
#include <iostream>
Timer::Timer()
{
//create a timer
mytimer = new QTimer(this);
//setup signal and slot
connect(mytimer,SIGNAL(timeout()),
this,SLOT(MyTimerSlot()));
mytimer->start(1000);
}
void Timer::MyTimerSlot()
{
std::cout << "\nMYtimerSlot";
}
4. Main.cpp 코딩
#include <QCoreApplication>
#include <iostream>
#include <QTimer>
#include "timer.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc,argv);
Timer mytimer;
std::cout << "\nHellow workd of craft (iostream)\n";
return a.exec();
}
반응형
'QT > Basic Tutorial' 카테고리의 다른 글
<QT> PyQt & QtDesigner 설치 (라즈베리파이4) (0) | 2021.03.04 |
---|---|
Blocking Slave Example (0) | 2020.12.21 |
<QT> 단축키 (0) | 2020.12.18 |
<QT> QT 설치하기 (Install)(라즈베리파이4) (0) | 2020.12.15 |
<QT 기초> "Hello world" in console (0) | 2020.12.14 |