#include "myclass.h"
#include <QDebug>
myclass::myclass()
{
}
void myclass::qdebug()
{
qDebug()<<"1234";
}
void myclass::init()
{
connect(&timer, &QTimer::timeout, this, &myclass::qdebug);
timer.start(1000);
}
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QDebug>
#include <QTimer>
class myclass:public QObject
{
Q_OBJECT
public:
myclass();
public:
void qdebug();
QTimer timer;
void init();
};
#endif // MYCLASS_H
#include <QCoreApplication>
#include "myclass.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
myclass class1;
class1.init();
return a.exec();
}
导入模块
QT += core
需要继承QObject类