Qt-Arm交叉编译以及调用虚拟键盘(中英)

环境:Qt5.15.1
交叉编译链:海思的板子,arm-himix200-linux-
demo代码:Qt-Qml混合编程

第一步:环境搭建

1:从官网下载源码https://download.qt.io/archive/qt/5.15/5.15.1/single/     qt-everywhere-src-5.15.1.tar.xz
2:解压源码包到你所需要的目录下,解压命令 (1)xz -d qt-everywhere-opensource-src-5.15.1.tar.xz
									(2)tar xvf  qt-everywhere-opensource-src-5.15.1.tar

3://修改交叉编译gcc
vi qt-everywhere-opensource-src-5.15.1/qtbase/mkspecs/linux-arm-gnueabi-g++/qmake.conf
将“arm-linux-gnueabi-”改为“arm-himix200-linux-”。

4:编译Qt
./configure -release -xplatform linux-arm-gnueabi-g++ -c++std c++11 -prefix /../../qt_vir_keyboard/qt_5.15.1_arm/ -opensource -confirm-license -make libs -no-opengl -nomake tools -nomake examples -nomake tests -skip qt3d -skip qtandroidextras -skip qtcanvas3d -skip qtconnectivity -skip qtdatavis3d -skip qtdoc -skip qtgamepad  -skip qtlocation -skip qtmacextras -skip qtmultimedia -skip qtnetworkauth -skip qtpurchasing -skip qtsensors -skip qtspeech -skip qttools -skip qtwebchannel -skip qtwebengine -skip qtwebsockets -skip qtwebview -skip qtwinextras -skip qtx11extras -no-feature-iconv -no-feature-gestures
PS:1、命令执行的当前路径是qt-everywhere-opensource-src-5.15.1/
   2、编译参数的选择可参考如下链接:
		 [编译Qt模块说明](http://c.biancheng.net/view/1842.html)
   3、交叉编译链的环境变量配置可自行百度,可修改配置文件,也可通过export PATH="":$PATH 命令,设置临时的

5:等待命令(执行完毕),执行完毕,会有提示信息,就是你配置安装脚本的一些详细说明,以及接下来的操作步骤

6:生成makefile,输入make即可,也可输入make -j4   make -j8

7:make install

总结:上述步骤执行完,如果没有报错,会在你步骤4指定的目录下生成目标文件-prefix /../../qt_vir_keyboard/qt_5.15.1_arm/

第二步:步骤一处理完,可将生成的交叉编译文件拷到板子上,运行程序,进行测试
ps:本人是在win上编写代码,然后,将代码考到linux服务器上,进行编译,再将可执行程序拷到设备上运行,编译及运行命令如下:

编译命令
cd /home/../
cd LoginDemoQml
export PATH="/nfs/../qt_vir_keyboard/qt_5.15.1_arm/bin":$PATH
qmake LoginDemoQml.pro
make 
cp -rf ../LoginDemoQml  /nfs/../
chmod 777 -R /nfs/../LoginDemoQml

运行命令
mount -t nfs -o nolock 192.168.3.28:/nfs/ /nfsroot/

export QT_ROOT=/mnt/qt_5.15.1_arm
export PATH=$QT_ROOT/bin:$PATH
export QML2_IMPORT_PATH=$QT_ROOT/qml
export LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$QT_ROOT/lib
export QT_QPA_PLATFORM_PLUGIN_PATH=$QT_ROOT/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0:mmsize=1920x1080:
export QT_QPA_FONTDIR=$QT_ROOT/lib/fonts

cd /nfsroot/../LoginDemoQml/
./LoginDemoQml -platform linuxfb


PS:运行时会提示很多字体找不到的警告,原因是在/mnt/qt_5.15.1_arm/lib/fonts没有字体库,需要额外添加进来
解决方法:将文件夹目录下的fonts.tar解压到/mnt/qt_5.15.1_arm/lib/fonts目录底下。至于fonts.tar压缩包一般的提供编译链(sdk)厂商都会随开发文档一起给予的,或者在网上搜一个

第三步:调用虚拟键盘
如若需要调用Qt的虚拟键盘,还需要如下配置和环境搭建,ps:以下操作是在步骤一基础上实现
1:编译支持中文的虚拟键盘库

  1. 进入拼音的源码目录:
    (1)cd qt-everywhere-src-5.15.1/qtvirtualkeyboard/src/plugins/pinyin
    (2)使用export PATH="": P A T H 设 置 编 译 环 境 变 量 如 : e x p o r t P A T H = " / n f s / . . / q t v i r k e y b o a r d / q t 5 . 15. 1 a r m / b i n " : PATH 设置编译环境变量 如:export PATH="/nfs/../qt_vir_keyboard/qt_5.15.1_arm/bin": PATHexportPATH="/nfs/../qtvirkeyboard/qt5.15.1arm/bin":PATH
    (3)qmake pinyin.pro,生成Makefile。
    (4)make,生成拼音的库。

  2. 进入/qt-everywhere-src-5.15.1/qtvirtualkeyboard/src/virtualkeyboard/目录,修改virtualkeyboard.pro,在Pro文件中对应的位置加入红色框的内容:在这里插入图片描述

  3. 进入qt-everywhere-src-5.15.1/qtvirtualkeyboard目录:
    1:使用export PATH="": P A T H 设 置 编 译 环 境 变 量 如 : e x p o r t P A T H = " / n f s / . . / q t v i r k e y b o a r d / q t 5 . 15. 1 a r m / b i n " : PATH 设置编译环境变量 如:export PATH="/nfs/../qt_vir_keyboard/qt_5.15.1_arm/bin": PATHexportPATH="/nfs/../qtvirkeyboard/qt5.15.1arm/bin":PATH
    2:qmake qtvirtualkeyboard.pro
    3:make
    4:make install

  4. 将步骤一/…/…/qt_vir_keyboard/qt_5.15.1_arm/的文件夹重新拷入开发版,运行并测试

最后,贴出主要的代码

在pro文件中,添加如下代码
static{
	QTPLUGIN+=qtvirtualkeyboardplugin
	QT+=svg
}
/在main.cpp中添加如下
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
测试的qml文件代码

import添加组件
import QtQml 2.2
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.VirtualKeyboard 2.15

Window { 
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Item{ 不可见元素
        id:root ///唯一的标识
        width: 200  
        height: 100
        anchors.left: parent.left  /布局
        anchors.top: parent.top
        TextField{   可输入元素
            id:_textField 
            anchors.left: parent.left
            anchors.top: parent.top
            //anchors.right: parent.right
            //anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottom:_inputPannel.top
        }

        InputPanel{  ///Provides the virtual keyboard UI,提供虚拟键盘窗口,详细说明可查看帮助文档
            id: _inputPannel
            //width:100 ///虚拟键盘的宽度
            y:Qt.inputMethod.visible ? parent.height - _inputPannel.height - 100 : parent.height   /虚拟键盘的y轴位置
            anchors.left: parent.left ///这些布局与width互斥
            anchors.right: parent.right
        }
    }


}

以下贴出demo运行的图片
在这里插入图片描述
在这里插入图片描述

 写在最后:不足之处,请多多理解,并指出,共同进步!
 本文参考:https://blog.csdn.net/u012391388/article/details/78485365
  • 5
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
要在Ubuntu上配置Qt-arm交叉编译环境,您需要执行以下步骤: 1. 安装交叉编译工具链 您可以使用以下命令安装交叉编译工具链: ``` sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi ``` 2. 下载Qt 您可以从Qt官网下载Qt for Embedded Linux的源代码。解压缩下载的文件并将其放在您选择的目录中。 3. 配置Qt 进入解压后的Qt目录,执行以下命令: ``` ./configure -xplatform qws/linux-arm-gnueabi-g++ -embedded arm -little-endian -prefix /usr/local/qt-arm -no-largefile -no-accessibility -no-qt3support -no-sql-sqlite -no-glib -no-cups -no-pch -no-mmx -no-3dnow -no-sse -no-sse2 -no-ssse3 -no-sse3 -no-sse4.1 -no-sse4.2 -no-avx -no-neon -no-openvg -no-gtkstyle -no-nis -no-iconv -no-dbus -no-opengl -no-rpath -no-gif -no-libtiff -no-libpng -no-libmng -no-libjpeg -no-openssl -no-nas-sound -no-pulseaudio -no-alsa -no-xinerama -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xinput -no-xkb -no-sm -no-xshape -no-xvidmode -no-xinerama -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-xinput -no-xkb -no-sm -no-xshape -no-xvidmode ``` 请注意,此命令假定您已经安装了arm交叉编译工具链,并且将Qt安装到了/usr/local/qt-arm目录中。 4. 编译Qt 执行以下命令编译Qt: ``` make ``` 这将需要一些时间来完成。 5. 安装Qt 执行以下命令安装Qt: ``` sudo make install ``` 6. 配置环境变量 将以下行添加到您的~/.bashrc文件中: ``` export PATH=/usr/local/qt-arm/bin:$PATH ``` 这将使您能够在命令行中轻松访问Qt。 完成以上步骤后,您应该已经成功配置了Qt-arm交叉编译环境。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值