参考1:https://blog.csdn.net/lbsljn/article/details/51789892
参考2:https://blog.csdn.net/coekjin/article/details/52049273
sudo apt-get install qt5-default
sudo apt-get install qtcreator
如果发现安装失败,参考3:https://blog.csdn.net/liuhanhan512/article/details/7738700
sudo aptitude install qt5-default
sudo aptitude install qtcreator
安装成功后就可以在编程工具里面找到QT creator的图标了。
工具——>选项——>构建与运行。
名称——桌面,(默认的);
设备类型——桌面;
设备——Local PC;
其他的编译器(/usr/bin/gcc),调试器(/usr/bin/gdb),Cmake(/有usr/bin/qmake),暂时先不设置,在后面的选项框继续设置。qt版本使自动生成。
点击添加C++找到根目录下的/usr/bin/gcc;C找到根目录下的/usr/bin/gcc。
查看构建套件(kit)选项,是否全部都如上述的设置的一致。
我的LED小灯有两个引脚线,连接电阻的那头连接正极,连接到物理位置为11的引脚。对应wiringPi的GPIO0脚。
LED的另外一条线接地,连接到物理位置为20的引脚。下图的黄线就是要接的引脚。
参考:https://blog.csdn.net/coekjin/article/details/52049273
下面我自己写的程序:
新建一个项目(不带Ui)。
#配置文件helloraspi180408.pro的内容。
#-------------------------------------------------
#
# Project created by QtCreator 2018-04-08T13:43:24
#
#-------------------------------------------------
QT += core gui
LIBS += -lwiringPi
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = helloraspi180408
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp\
helloraspi.cpp
HEADERS += helloraspi.h
#ifndef HELLORASPI_H
#define HELLORASPI_H
#include
#include
class helloraspi : public QMainWindow
{
Q_OBJECT
QPushButton *turn_on_Button;
QPushButton *turn_off_Button;
public:
helloraspi(QWidget *parent = 0);
~helloraspi();
public slots:
void turn_on_Button_slots();
void turn_off_Button_slots();
};
#endif // HELLORASPI_H
#include "helloraspi.h"
#include "wiringPi.h"
helloraspi::helloraspi(QWidget *parent)
: QMainWindow(parent)
{
this->resize(300,250);//width,high
turn_on_Button=new QPushButton("turn on",this);
turn_off_Button=new QPushButton("turn off",this);
turn_on_Button->setGeometry(50,20,200,50);//left,on,length,width
turn_off_Button->setGeometry(50,100,200,50);
connect(turn_on_Button,SIGNAL(clicked()),this,SLOT(turn_on_Button_slots()));
connect(turn_off_Button,SIGNAL(clicked()),this,SLOT(turn_off_Button_slots()));
wiringPiSetup();//initialization
pinMode(0,OUTPUT);//set output
digitalWrite(0,LOW);//output 0/low
}
void helloraspi::turn_on_Button_slots()
{
digitalWrite(0,HIGH);
}
void helloraspi::turn_off_Button_slots()
{
digitalWrite(0,LOW);
}
helloraspi::~helloraspi()
{
}
#include "helloraspi.h"
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
helloraspi w;
w.show();
w.move ((QApplication::desktop()->width() - w.width())/2,(QApplication::desktop()->height() - w.height())/2);//居中
return a.exec();
}
点击turn on按钮,点亮小灯。
点击turn off按钮,熄灭小灯。