您现在的位置是:网站首页> C/C++

树莓派第一个QT程序

  • C/C++
  • 2022-07-03
  • 795人已阅读
摘要

我的QT第一个程序MyQT

MyQT.pro添加库

LIBS += -lwiringPi

1.png

mainwindow.h

#ifndef MAINWINDOW_H

#define MAINWINDOW_H


#include <QMainWindow>

#include <wiringPi.h>


namespace Ui {

class MainWindow;

}


class MainWindow : public QMainWindow

{

    Q_OBJECT


public:

    explicit MainWindow(QWidget *parent = 0);

    ~MainWindow();


private slots:

    void on_pushButton_clicked();


    void on_pushButton_2_clicked();


    void on_pushButton_3_clicked();


    void on_pushButton_4_clicked();


private:

    int LEDPort;

    Ui::MainWindow *ui;

};


#endif // MAINWINDOW_H

mainwindow.cpp

include "mainwindow.h"

#include "ui_mainwindow.h"


MainWindow::MainWindow(QWidget *parent) :

    QMainWindow(parent),

    ui(new Ui::MainWindow)

{

    LEDPort=5;

    ui->setupUi(this);

    wiringPiSetup();

    pinMode(LEDPort,OUTPUT);

}


MainWindow::~MainWindow()

{

    delete ui;

}


void MainWindow::on_pushButton_clicked()

{

    this->setWindowFlags (Qt::Window);

    this->showFullScreen ();

}


void MainWindow::on_pushButton_2_clicked()

{

    this->setWindowFlags (Qt::SubWindow);

    this->showNormal ();

}


void MainWindow::on_pushButton_3_clicked()

{

    digitalWrite(LEDPort,HIGH);

}


void MainWindow::on_pushButton_4_clicked()

{

    digitalWrite(LEDPort,LOW);

}


Top