QTimer signalSlot
//-------------------- .h -----------------------------
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>#include <QTimer>#include <QDebug>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);~MainWindow();private slots:void updates();private:
Ui::MainWindow *ui;QTimer *timer;};#endif // MAINWINDOW_H
//------------------------ .cpp ----------------
#include "mainwindow.h"
#include "ui_mainwindow.h"
int cnt =0;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(updates()));
timer->start(300);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::updates(){
cnt++;
qDebug() << "Timer = " << cnt;
}
0 ความคิดเห็น:
แสดงความคิดเห็น
สมัครสมาชิก ส่งความคิดเห็น [Atom]
<< หน้าแรก