1.Ubuntu Qt 配置交叉編譯環(huán)境
1.1 ubuntu 20.04安裝Qt
sudo apt-get install qtcreator
1.2 配置QT
?
?GCC配置同上
?
最后配置Kits
上面設(shè)置完成之后 ,設(shè)置Kits 中的Device(這是為了能夠直接把項目部署到arm設(shè)備上)
?
?
?點擊NEXT之后會出現(xiàn)連接被拒絕,不用擔心 ,下面會對其設(shè)置密碼。
驗證arm設(shè)置的密碼。
?
?
?
?1.3 創(chuàng)建Qt項目
?
?
?
?
?
代碼:
此代碼是抄的別人的,具體是哪位博主的,忘記了。如果該博主看到了 請@下我,我會把連接附上
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
? ?QApplication a(argc, argv);
? ?Widget w;
? ?w.show();
? ?return a.exec();
}
widget.cpp
#include "widget.h"
#include<QPainter>
#include<QTimer>
#include<QTime>
#include<QString>
#include<QVector>
#include<QMap>
#define CLOCK_RADIUS (80) //時鐘的半徑
#define PANEL_RADIUS_NUM (3) //表盤的3個圓
#define PANEL_RADIUS1 CLOCK_RADIUS //圓1的半徑
#define PANEL_RADIUS2 (CLOCK_RADIUS - 6) //圓2的半徑
#define PANEL_RADIUS3 (CLOCK_RADIUS - 8) //圓3的半徑
#define HOUR_NUM_SIZE (10) //小時數(shù)字的字體大小
//3個表針的形狀(三角形)
static QPoint hourHand[3] = {
? ?QPoint(5, 3),
? ?QPoint(-5, 3),
? ?QPoint(0, -30)
};
static QPoint minuteHand[3] = {
? ?QPoint(4, 6),
? ?QPoint(-4, 6),
? ?QPoint(0, -45)
};
static QPoint secondHand[3] = {
? ?QPoint(2, 10),
? ?QPoint(-2, 10),
? ?QPoint(0, -60)
};
//表針與刻度顏色
static QColor hourColor(255, 0, 0);
static QColor minuteColor(0, 0, 255);
static QColor secondColor(0, 255, 0);
//表盤參數(shù)
struct panelPara{
? ?int radius;
? ?QColor color;
};
//圓的半徑與對于的顏色
static panelPara stPanelParaArr[] = {
? {PANEL_RADIUS1, QColor(255, 200, 100)},
? {PANEL_RADIUS2, QColor(164, 211, 238)},
? {PANEL_RADIUS3, QColor(255, 255, 255)},
};
Widget::Widget(QWidget *parent)
? : QWidget(parent)
{
? ?QTimer *timer = new QTimer(this);
? ?connect(timer, SIGNAL(timeout()), this, SLOT(update()));
? ?timer->start(1000);
? ?setWindowTitle(tr("Clock"));
? ?setMinimumSize(200, 200); //設(shè)置最小尺寸
}
Widget::~Widget()
{
}
void Widget::paintEvent(QPaintEvent *event)
{
? ?int side = qMin(width(), height());
? ?QTime time = QTime::currentTime();
? ?QPainter painter(this);
? ?painter.setRenderHint(QPainter::Antialiasing);
? ?painter.translate(width()/2, height()/2); //畫圖的基準位置
? ?painter.scale(side/200.0, side/200.0); //隨窗口尺寸自動縮放
? ?//表盤
? ?for (int i=0; i<PANEL_RADIUS_NUM; i++)
? {
? ? ? ?QBrush brush(stPanelParaArr[i].color);
? ? ? ?QPen pen(stPanelParaArr[i].color);
? ? ? ?painter.setBrush(brush);
? ? ? ?painter.setPen(pen);
? ? ? ?painter.drawEllipse(-stPanelParaArr[i].radius, -
stPanelParaArr[i].radius, 2*stPanelParaArr[i].radius,
2*stPanelParaArr[i].radius);
? }
? ?//小時的表針
? ?painter.setPen(Qt::NoPen);
? ?painter.setBrush(hourColor);
? ?painter.save();
? ?painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
? ?painter.drawConvexPolygon(hourHand, 3);
? ?painter.restore();
? ?//小時的刻度
? ?painter.setPen(hourColor);
? ?for (int i = 0; i < 12; ++i)
{
? ? ? ?painter.rotate(30.0);
? ? ? ?painter.drawLine(PANEL_RADIUS3-6, 0, PANEL_RADIUS3, 0);
? ? ? ?QFont font("TimesNewRoman", HOUR_NUM_SIZE);
? ? ? ?painter.setFont(font);
? ? ? ?painter.drawText(-HOUR_NUM_SIZE, -(CLOCK_RADIUS-15), 2*HOUR_NUM_SIZE,
2*HOUR_NUM_SIZE, Qt::AlignHCenter, QString::number(i+1));
? }
? ?//分鐘的表針
? ?painter.setPen(Qt::NoPen);
? ?painter.setBrush(minuteColor);
? ?painter.save();
? ?painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
? ?painter.drawConvexPolygon(minuteHand, 3);
? ?painter.restore();
? ?painter.setPen(minuteColor);
? ?for (int j = 0; j < 60; ++j)
? {
? ? ? ?if ((j % 5) != 0)
? ? ? {
? ? ? ? ? ?painter.drawLine(PANEL_RADIUS3-4, 0, PANEL_RADIUS3, 0);
? ? ? }
? ? ? ?painter.rotate(6.0);
? }
? ?//秒鐘的表針
? ?painter.setPen(Qt::NoPen);
? ?painter.setBrush(secondColor);
? ?painter.save();
? ?painter.rotate(6.0 * time.second());
? ?painter.drawConvexPolygon(secondHand, 3);
? ?painter.restore();
? ?painter.end();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class Widget : public QWidget
{
? ?Q_OBJECT
public:
? ?Widget(QWidget *parent = nullptr);
? ?~Widget();
? ?void paintEvent(QPaintEvent *event);
};
#endif // WIDGET_H
配置 clock.pro ,在pro文件添加下面代碼。
#要部署的到ARM設(shè)備上的目錄
target.path=/opt/arm #安裝目標文件
INSTALLS+=target
先對項目進行編譯,再把項目發(fā)布到 arm設(shè)備。
?上面項目部署之后,登陸arm設(shè)備進到對應的目錄下查看代碼。
?查看生成的文件 格式, 為arm aarch 64 正是arm 設(shè)備運行的文件 。
?
?執(zhí)行命令運行程序,如下
nvidia@ubuntu:/opt/clock/bin$ ./clock
?
?文章來源:http://www.zghlxwxcb.cn/news/detail-669342.html
2.windows下使用visual studio或qt進行
arm linux程序開發(fā)環(huán)境搭建
2.1 創(chuàng)建項目
?
?
?
?
?
?widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include<QPainter>
#pragma execution_character_set("utf-8")
Widget::Widget(QWidget *parent) :
? QWidget(parent),
? ui(new Ui::Widget)
{
? ui->setupUi(this);
? connect(&timer, SIGNAL(timeout()), this, SLOT(timeout_slot()));
? connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
? connect(ui->Btn_Reset, SIGNAL(clicked()), this, SLOT(update()));
? time.setHMS(0,0,0,0);
? ui->Txt_ShowTime->setText("00:00:00");
? ui->Btn_Start->setChecked(false);
? ui->Btn_Reset->setEnabled(false);
? ui->Btn_Hit->setEnabled(false);
}
Widget::~Widget()
{
? delete ui;
}
void Widget::timeout_slot()
{
? //qDebug("hello");
? QTime nowTime = QTime::currentTime();
? time = time.addMSecs(lastTime.msecsTo(nowTime));
? lastTime = nowTime;
? ui->Txt_ShowTime->setText(time.toString("mm:ss.zzz"));
}
void Widget::on_Btn_Start_toggled(bool checked)
{
? ?if (checked)
? {
? ? ? timer.start(ADD_TIME_MSEC);
? ? ? lastTime = QTime::currentTime();//記錄時間戳
? ? ? ui->Btn_Start->setText("暫停");
? ? ? ui->Btn_Reset->setEnabled(false);
? ? ? ui->Btn_Hit->setEnabled(true);
? }
? ?else
? {
? ? ? timer.stop();
? ? ? ui->Btn_Start->setText("繼續(xù)");
? ? ? ui->Btn_Reset->setEnabled(true);
? ? ? ui->Btn_Hit->setEnabled(false);
? }
}
void Widget::on_Btn_Reset_clicked()
{
? m_iHitCnt = 0;
? timer.stop();
? time.setHMS(0,0,0,0);
? ui->Txt_ShowTime->setText("00:00:00");
? ui->Txt_ShowItem->clear();
? ui->Btn_Start->setText("開始");
? ui->Btn_Start->setChecked(false);
? ui->Btn_Reset->setEnabled(false);
? ui->Btn_Hit->setEnabled(false);
}
void Widget::on_Btn_Hit_clicked()
{
? QString temp;
? m_iHitCnt++;
? temp.sprintf("--計次 %d--", m_iHitCnt);
? ui->Txt_ShowItem->setFontPointSize(9);
? ui->Txt_ShowItem->append(temp);
? ui->Txt_ShowItem->setFontPointSize(12);
? ui->Txt_ShowItem->append(time.toString("[mm:ss.zzz]"));
}
//------------------
#define CLOCK_RADIUS (90) //時鐘的半徑
#define PANEL_RADIUS_NUM (3) //表盤的3個圓
#define PANEL_RADIUS1 CLOCK_RADIUS //圓1的半徑
#define PANEL_RADIUS2 (CLOCK_RADIUS - 6) //圓2的半徑
#define PANEL_RADIUS3 (CLOCK_RADIUS - 8) //圓3的半徑
#define PANEL_RADIUS4 (40) //內(nèi)圓的半徑
#define SEC_NUM_SIZE (10) //小時數(shù)字的字體大小
#define MIN_NUM_SIZE (7) //分鐘數(shù)字的字體大小
//3個表針的形狀(三角形)
static QPoint minuteHand[3] = {
QPoint(2, 6),
? QPoint(-2, 6),
? QPoint(0, -45)
};
static QPoint secondHand[3] = {
? QPoint(2, 8),
? QPoint(-2, 8),
? QPoint(0, -85)
};
//表針與刻度顏色
static QColor secondColor(0, 0, 255);
static QColor minuteColor(0, 0, 0);
//表盤參數(shù)
struct panelPara{
? int radius;
? QColor color;
};
//圓的半徑與對于的顏色
static panelPara stPanelParaArr[] = {
? {PANEL_RADIUS1, QColor(255, 200, 100)},
? {PANEL_RADIUS2, QColor(164, 211, 238)},
? {PANEL_RADIUS3, QColor(255, 255, 255)},
};
void Widget::paintEvent(QPaintEvent *event)
{
? int side = qMin(width(), height());
? //QTime time = QTime::currentTime();
? QPainter painter(this);
? painter.setRenderHint(QPainter::Antialiasing);
? painter.translate(width()/3, height()*2/5); //畫圖的基準位置
? painter.scale(side/300.0, side/300.0); //隨窗口尺寸自動縮放
? //表盤(3個同心圓)
? ?for (int i=0; i<PANEL_RADIUS_NUM; i++)
? {
? ? ? QBrush brush(stPanelParaArr[i].color);
? ? ? QPen pen(stPanelParaArr[i].color);
? ? ? painter.setBrush(brush);
? ? ? painter.setPen(pen);
? ? ? painter.drawEllipse(-stPanelParaArr[i].radius, -stPanelParaArr[i].radius,
2*stPanelParaArr[i].radius, 2*stPanelParaArr[i].radius);
? }
? //秒的刻度
? painter.setPen(secondColor);
? ?for (int i = 0; i < 60; i++)
? {
? ? ? ?if ((i % 5) == 0)
? ? ? {
? ? ? ? ? painter.drawLine(PANEL_RADIUS3-8, 0, PANEL_RADIUS3, 0);
? ? ? ? ? QFont font("TimesNewRoman", SEC_NUM_SIZE);
? ? ? ? ? painter.setFont(font);
? ? ? ? ? painter.drawText(-SEC_NUM_SIZE, -(CLOCK_RADIUS-15), 2*SEC_NUM_SIZE,
2*SEC_NUM_SIZE, Qt::AlignHCenter, QString::number(i==0? 60 : i));
}
? ? ? ?else
? ? ? {
? ? ? ? ? painter.drawLine(PANEL_RADIUS3-5, 0, PANEL_RADIUS3, 0);
? ? ? }
? ? ? //秒再細分5個格
? ? ? ?for (int j = 0; j < 5; j++)
? ? ? {
? ? ? ? ? painter.rotate(6.0/5);
? ? ? ? ? ?if (j != 4)
? ? ? ? ? {
? ? ? ? ? ? ? painter.drawLine(PANEL_RADIUS3-2, 0, PANEL_RADIUS3, 0);
? ? ? ? ? }
? ? ? }
? }
? //分鐘的刻度
? painter.setPen(minuteColor);
? ?for (int k = 0; k < 30; k++)
? {
? ? ? ?if ((k % 5) == 0)
? ? ? {
? ? ? ? ? painter.rotate(-90.0);
? ? ? ? ? painter.drawLine(PANEL_RADIUS4-8, 0, PANEL_RADIUS4, 0);
? ? ? ? ? painter.rotate(90.0);
? ? ? ? ? QFont font("TimesNewRoman", MIN_NUM_SIZE);
? ? ? ? ? painter.setFont(font);
? ? ? ? ? painter.drawText(-MIN_NUM_SIZE, -(PANEL_RADIUS4-10), 2*MIN_NUM_SIZE,
2*MIN_NUM_SIZE, Qt::AlignHCenter, QString::number(k==0? 30 : k));
? ? ? }
? ? ? ?else
? ? ? {
? ? ? ? ? painter.rotate(-90.0);
? ? ? ? ? painter.drawLine(PANEL_RADIUS4-4, 0, PANEL_RADIUS4, 0);
? ? ? ? ? painter.rotate(90.0);
? ? ? }
? ? ? painter.rotate(12.0);
? }
? //分鐘的表針
? painter.setPen(Qt::NoPen);
? painter.setBrush(minuteColor);
? painter.save();
? painter.rotate(12.0 * (time.minute() + time.second() / 60.0));
? painter.drawConvexPolygon(minuteHand, 3);
? painter.restore();
? //秒鐘的表針
? painter.setPen(Qt::NoPen);
? painter.setBrush(secondColor);
? painter.save();
? //painter.rotate(6.0 * time.second());
? painter.rotate(6.0 * (time.second()+time.msec()/1000.0));
? painter.drawConvexPolygon(secondHand, 3);
? painter.restore();
? painter.end();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QTimer>
#include <QTime>
#include <QDebug>
#define ADD_TIME_MSEC 30
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
? Q_OBJECT
public:
? explicit Widget(QWidget *parent = nullptr);
? ~Widget();
? void paintEvent(QPaintEvent *event);
? QTimer timer;
? QTime time;
? QTime lastTime;
private slots:
? void on_Btn_Start_toggled(bool checked);
? void timeout_slot();
? void on_Btn_Reset_clicked();
? void on_Btn_Hit_clicked();
private:
? Ui::Widget *ui;
? int m_iHitCnt = 0;
};
#endif // WIDGET_H
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
? QApplication a(argc, argv);
? Widget w;
? w.show();
? return a.exec();
}
?2.2 運行項目
?
?2.3把文件移動到Linux下
在win下編譯通過之后,把文件 main.cpp timer.pro widget.cpp widget.h widget.ui 移動到
Linux 下
?用編譯源碼生成的 qmake(前面2. Linux Server 20.04 Qt5.14.2配置Jetson Orin Nano Developer Kit 交叉編譯環(huán)境?生成的qmake) 進行對 timer.pro 文件進行編譯
/opt/Qt5JetsonOrinNano/sysroot/usr/local/Qt5JetsonOrinNano/bin/qmake timer.pro
之后會生成 Makefile 文件
再執(zhí)行 make 命令
?生成 .o 文件
?
?輸入命令 file timer 查看生成的 timer 文件 類型
?把文件拷貝到 arm 設(shè)備
scp ./timer nvidia@192.168.20.230:/home/nvidia/Downloads/test/time
?
?
sudo vim /etc/profile
#加入下面5行代碼
export QT_DEBUG_PLUGINS=1
export QTDIR=/usr/local/Qt5JetsonOrinNano#編譯的源碼
export LD_LIBRARY_PATH=/usr/local/Qt5JetsonOrinNano/lib:$LD_LIBRARY_PATH
export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins
export QT_QPA_PLATFORM=xcb#編譯源碼時加入的顯示模塊 -xcb
sudo source /etc/profile
?文章來源地址http://www.zghlxwxcb.cn/news/detail-669342.html
到了這里,關(guān)于3:Ubuntu上配置QT交叉編譯環(huán)境并編譯QT程序到Jetson Orin Nano(ARM)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!