QT开发实战一:图片显示
阅读原文时间:2023年07月08日阅读:1

宿主机平台:Ubuntu 12.04.4 LTS

目标机:Easy-ARM IMX283

目标机内核:Linux 2.6.35.3

QT版本:Qt-4.7.3

Tslib版本:tslib-1.0.0

整个测试均放在上节制作的文件系统,通NFS根文件系统来进行测试

1.tslib编译

编译与安装

./autogen.sh
./configure --prefix=$(pwd)/install --host=arm-linux ac_cv_func_malloc_0_nonnull=yes CC=arm-none-linux-gnueabi-gcc
make
make install

将安装文件拷贝到 /home/vmuser/workspace/vm_tools/tslib

修改 tslib/etc/ts.conf

2.qt-4.7.3源码编译

编译与安装

./configure -prefix /home/vmuser/workspace/vm_tools/qt-4.7.3-arm -opensource -confirm-license -release -shared -embedded arm -xplatform qws/linux-arm-gnueabi-g++ -depths 16,18,24,32 -fast -lrt -little-endian -optimized-qmake -pch -qt-sql-sqlite -qt-zlib -qt-libjpeg -qt-libpng -qt-freetype -no-largefile -no-accessibility -no-qt3support -no-webkit -no-mmx -no-3dnow -no-sse -no-sse2 -no-glib -no-libtiff -no-libmng -no-openssl -nomake examples -nomake docs -nomake demos -no-separate-debug-info -no-qvfb -no-cups -no-gtkstyle -no-xrender -no-glib -qt-mouse-pc -qt-mouse-linuxtp -qt-mouse-tslib -qt-mouse-linuxinput -qt-kbd-linuxinput -qt-gfx-linuxfb -qt-gfx-transformed -D QT_QWS_CLIENTBLIT -I /home/vmuser/workspace/vm_tools/tslib/include -L /home/vmuser/workspace/vm_tools/tslib/lib

修改 qt-everywhere-opensource-src-4.7.3/mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf 文件

然后 编译、安装

make

make install

添加 qmake-arm 变量别名,便于以后编译程序移植

vi ~/.bashrc
文件末尾添加:

alias qmake-arm=/home/vmuser/workspace/vm_tools/qt-4.7.3-arm/bin/qmake

3. 移植tslib和qt的库

1. 拷贝库文件到文件系统

/home/vmuser/workspace/vm_tools/tslib

/home/vmuser/workspace/vm_tools/qt-4.7.3-arm

到 /home/vmuser/workspace/myrootfs/usr/local

2. 修改启动初始化脚本,配置 qt 运行环境

修改 myrootfs/etc/profile

export TSLIB_ROOT=/usr/local/tslib
export TSLIB_TSDEVICE=/dev/input/event0
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
export TSLIB_FBDEVICE=/dev/fb0
export QWS_MOUSE_PROTO=tslib:/dev/input/event0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TSLIB_ROOT/lib

export QTDIR=/usr/local/qt-4.7.3
export LD_LIBRARY_PATH=$QTDIR/lib:$QTDIR/plugins/imageformats:$LD_LIBRARY_PATH
export QT_PLUGIN_PATH=$QTDIR/plugins
export QT_QWS_FONTDIR=$QTDIR/lib/fonts

要同时支持鼠标时添加

export QWS_MOUSE_PROTO="tslib:/dev/input/event0 MouseMan:/dev/input/mouse0"

4. NFS跟文件系统启动测试

新建 home 文件夹,将QT交叉编译后的程序拷贝到 home

进入uboot 设置NFS启动参数

setenv bootargs 'root=/dev/nfs rw console=ttyAM0,115200n8 nfsroot=192.168.1.123:/home/vmuser/workspace/myrootfs ip=192.168.1.124:192.168.1.123:192.168.1.254:255.255.255.0:epc.zlgmcu.com:eth0:off mem=64M'

saveenv

然后 reset 开机从 myrootfs 启动

ui 界面设置如下,使用水平、垂直布局工具对齐

showpic.cpp代码如下:

#include "showpic.h"
#include "ui_showpic.h"

showpic::showpic(QWidget *parent) :
QWidget(parent),
ui(new Ui::showpic)
{
ui->setupUi(this);

QPixmap pix = QPixmap("/home/picture/bk1.jpg");  
pix.scaledToHeight(200);  
pix.scaledToWidth(300);  
ui->labelPic->setPixmap(pix);  
ui->label->setText("123456");  

}

showpic::~showpic()
{
delete ui;
}

void showpic::on_pBtnShow_clicked()
{
QPixmap pix = QPixmap("/home/picture/bk1.jpg");
pix.scaledToHeight(200);
pix.scaledToWidth(300);

ui->labelPic->setPixmap(pix);

ui->label->setText("123456");  

}

void showpic::on_pBtnHide_clicked()
{
ui->labelPic->clear();
ui->label->setText("hello,world…");
}

main.cpp

#include
#include "showpic.h"
#include //中文编码支持头文件
#include
#include "ui_showpic.h" //ui头文件
//using namespace Ui;

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));

showpic \*window = new showpic;

// window->resize(pix.height(), pix.width());
window->setWindowTitle("图片");
window->show();
// window->showFullScreen(); //全屏显示

return a.exec();  

}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章