Hello everyone,
This is a basic issue, but i didnt understand why I am failed timer slots. I used Qt 5.7 in console application timer isn't fired timeout signal.
#include <QCoreApplication>
#include "mytimer.h"
#include <QThread>
int main(int argc, char *argv[])
{
MyTimer* myTimer = new MyTimer();
while(true)
{
}
return a.exec();
}
#ifndef MYTIMER_H
#define MYTIMER_H
#include <QObject>
#include <QTimer>
{
Q_OBJECT
public:
explicit MyTimer
(QObject *parent
= 0);
signals:
public slots:
void TimerTick();
};
#endif // MYTIMER_H
#include "mytimer.h"
#include "iostream"
{
timerObj->setInterval(1000);
connect(timerObj,SIGNAL(timeout()),this,SLOT(TimerTick()));
timerObj->start();
}
void MyTimer::TimerTick()
{
std::cout << "Timer Interrupt" << std::endl;
}
#include <QCoreApplication>
#include "mytimer.h"
#include <QThread>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyTimer* myTimer = new MyTimer();
while(true)
{
QThread::yieldCurrentThread();
}
return a.exec();
}
#ifndef MYTIMER_H
#define MYTIMER_H
#include <QObject>
#include <QTimer>
class MyTimer : public QObject
{
Q_OBJECT
public:
explicit MyTimer(QObject *parent = 0);
QTimer* timerObj;
signals:
public slots:
void TimerTick();
};
#endif // MYTIMER_H
#include "mytimer.h"
#include "iostream"
MyTimer::MyTimer(QObject *parent) : QObject(parent)
{
timerObj = new QTimer(this);
timerObj->setInterval(1000);
connect(timerObj,SIGNAL(timeout()),this,SLOT(TimerTick()));
timerObj->start();
}
void MyTimer::TimerTick()
{
std::cout << "Timer Interrupt" << std::endl;
}
To copy to clipboard, switch view to plain text mode
Bookmarks