Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QThread>
- class mthread : public QThread{ //dziedziczenie po qthread
- Q_OBJECT
- public:
- explicit mthread(QObject *parent = 0);
- void run(); //funkcja run reimplementacja
- signals:
- public slots:
- };
- implementacja:
- #include "mthread.h"
- #include "wiringPi.h"
- #include<QDebug>
- mthread::mthread(QObject *parent) : QThread(parent)
- {
- qDebug()<<"konstruktor "<<QThread::currentThreadId(); //wątek główny
- }
- void mthread::run(){
- qDebug()<<"funkcja run "<<QThread::currentThreadId();
- wiringPiSetup();
- pinMode(0,OUTPUT);
- bool state=false;
- while(1){
- digitalWrite(0,state);
- state=!state;
- QThread::sleep(4); //migacz co 4 s;
- }
- }
- i wywołanie z klasy okna głównego
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- thread =new mthread(this);
- thread->start(); //start nowego wątku
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement