Hi, I have a problem in using QTimer.
I'm trying to use this piece of code, but I don't know why the function "cameraTimerTimeout()" doesn't start:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <iostream>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void cameraTimerTimeout();
void cattura();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include <iostream>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
void cameraTimerTimeout();
void cattura();
private:
Ui::MainWindow *ui;
QTimer cameraTimer;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
MainWindow w;
ui->pushButton->setText("Ferma riconoscimento");
w.cattura();
}
void MainWindow::cattura()
{
cameraTimer.start(33); // 33 ms = 30 fps
connect(&cameraTimer, SIGNAL(timeout()),this,SLOT(cameraTimerTimeout()));
return;
}
void MainWindow::cameraTimerTimeout()
{
std::cout << "CIAO2" << std::endl;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
MainWindow w;
ui->pushButton->setText("Ferma riconoscimento");
w.cattura();
}
void MainWindow::cattura()
{
cameraTimer.start(33); // 33 ms = 30 fps
connect(&cameraTimer, SIGNAL(timeout()),this,SLOT(cameraTimerTimeout()));
return;
}
void MainWindow::cameraTimerTimeout()
{
std::cout << "CIAO2" << std::endl;
}
To copy to clipboard, switch view to plain text mode
Thank you in advance!
Bookmarks