树莓派5 Qt安装及使用
一,安装qt
# 换源,这样可以快点
sudo apt-get -o Dir::Etc::SourceList="http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse" update
# 更新一下软件包索引
sudo apt update
# 安装qt
sudo apt install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools
# 安装qtcreator
sudo apt-get install qtcreator
# 安装其他依赖
sudo apt-get install qtdeclarative5-dev
sudo apt-get install libgles2-mesa-dev
sudo apt-get install libqt5serialport5-dev
如图已安装完成,可以点击打开,树莓派性能还是很强的,可以直接运行qtcreator,在线编辑和调试。
二,Hello world测试
工程创建这里就不演示了。
测试代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QPushButton"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setGeometry(0,0,1000,600);
QPushButton *btn ;
btn = new QPushButton(this);
btn->setText("hello world");
btn->setGeometry(200,200,200,80);
}
MainWindow::~MainWindow()
{
delete ui;
}
三,测试结果