// main.cpp
#include <QtCore/QCoreApplication>
#include "test.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
test t;
t.dostuff();
return a.exec();
}
// test.h
#pragma once
#include <QObject>
#include <qdebug.h>
#include <qtimer.h>
#include <qtimezone.h>
class test : public QObject
{
Q_OBJECT
public:
explicit test(QObject *parent = nullptr);
~test();
signals:
public slots:
void timeout();
void dostuff();
private:
QTimer timer;
int number;
};
// test.cpp
#include "test.h"
test::test(QObject *parent)
: QObject(parent)
{
number = 0;
timer.setInterval(1000);
connect(&timer, &QTimer::timeout, this, &test::timeout);
}
test::~test()
{
}
void test::timeout()
{
number++;
qInfo() << QTime::currentTime().toString(Qt::DateFormat::SystemLocaleLongDate);
if (number == 5) {
timer.stop();
qInfo() << "Complete";
}
}
void test::dostuff()
{
timer.start();
}
