you can add test_encoder.cpp in mainwindow.cpp and should create a pointer of class in mainwindow.h like this:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <rotary_encoder.h>
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
rotary_encoderrotary_decoder *rc;
void callback(int way);
};
and use main.cpp as default:
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
rc=new rotary_encoderrotary_decoder();
//your code
//for call a function like:
rc.re_cancel();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::callback(int way)
{
static int pos = 0;
pos += way;
qDebug() << "pos=" << pos ;
}