QT: qtpy 抽象的QT API 库 与 Qt for MCU + PyQt6 to Android
https://www.riverbankcomputing.com/static/Docs/PyQt6/
https://www.qt.io/blog/taking-qt-for-python-to-android
https://github.com/shyamnathp/python-for-android/tree/pyside_support
一个非常好的 PyQT 实例 应用App 是 Anaconda 推出的 anaconda_navigator(兼容 Windows / Linux / MacOS),
安装完 Anaconda 之后,就可以查看到 Anaconda Navigator 的 PyQt 源码。
QT 的版本在不断的更新,为保证 QT5 / QT6 / pyqt6 / pyside6 多个库的 API 持续稳定,
因此出现 qtpy 这个抽象层库,类似 Python 的 six 库保障各版本的API统一。
pip install qtpy
PyQT6 和 PySide6 的:
import os
os.environ['QT_API'] = 'pyqt6' # OR: 'pyside6'
from qtpy import QtGui, QtWidgets, QtCore
print(QtWidgets.QWidget)
PySide is! - What's compatible with asyncio?
from PySide6.QtAsyncio import QAsyncioEventLoopPolicy
and
asyncio.set_event_loop_policy(QAsyncioEventLoopPolicy())
asyncio lets you replace its event loop with a custom implementation, and such a custom implementation is exactly what we have been doing.
This allows you to use the asyncio API and run programs that use asyncio or frameworks based on asyncio,
this puts the entire Qt API at asyncio's disposal, enabling you to mix and match code from asyncio and Qt, leveraging asyncio's async/await syntax.
Today, with the first release of the 6.6 cycle, we offer a technical preview of this event loop implementation,
letting you create futures, tasks, and handles, and manage the event loop lifecycle,
with wide coverage of the full event loop API to be built up over the upcoming minor releases.
Using Qt's event loop is as simple as adding these two lines to your code:
https://www.qt.io/blog/qt-for-mcus-2.5.2-lts-released
Qt for MCUs 2.5.2 LTS (Long-Term Support) has been released and is available for download. As a patch release, Qt for MCUs 2.5.2 LTS provides bug fixes and other improvements, and maintains source compatibility with Qt for MCUs 2.5.x. It does not add any new functionality.
For more information about fixed bugs, please check the Qt for MCUs 2.5.2 changelog.
As with other Qt products, Qt for MCUs 2.5.2 LTS can be added to an existing installation by using the maintenance tool or via a clean installation using Qt Online Installer.
More patch releases for Qt for MCUs 2.5 LTS are planned until December 2024, which is the end of the standard support period for that LTS version.
Taking Qt for Python to Android
April 19, 2023 by Shyamnath Premnadh | Comments
Deploying Python applications to Android is a big talking point these days among the Python community, and a frequently asked question by people developing their first GUI applications. There are already a couple of Python frameworks that offer the ability to deploy your applications to Android devices, and Qt for Android has existed for a decade now. With QML and Qt Quick, one can use Qt to develop native Android applications. It was high time we bridged the gap and brought PySide applications to Android.
With the new 6.5 release, we give you a new CLI tool, pyside6-android-deploy, that provides an easy interface to deploy your PySide6 application .
Technical Details
Currently, this tool is only available on Linux-based environments, and only a subset of the Qt modules are supported (see Considerations).
This tool uses a custom fork of the python-for-android project with a custom Qt bootstrap and recipes for PySide6 and shiboken6. The reason for using python-for-android instead of androiddeployqt is that python-for-android already provides a way to package the Python interpreter, which is by default not pre-installed on Android platforms. It can also be easily extended to include new Python packages, even those with a C/C++ backend. python-for-android already supports many popular Python packages like numpy, pandas, etc.
The entire deployment process is a 3-step process, where the first two steps need to be done only once per Android platform. The first two steps are setting up and cross-compiling Qt for Python wheels required for pyside6-android-deploy to work.
Steps to deploy your PySide application to Android
As mentioned above, Steps 1 and 2 need to be done only once for a specific Android architecture. Each PySide6 application that you deploy will use the same Qt for Python wheels.
Step 1: Setting up prerequisites
The Android dependencies for PySide6 are the same dependencies as those for Qt for Android. This step involves downloading the JDK, Android NDK, and Android SDK. You may skip this step if you already have them downloaded and set up. The recommended NDK version for PySide6 version 6.5 is r25. You can either use Qt Creator to install all the dependencies or install the dependencies manually, as shown below.
- Install JDK 11 or above. See instructions here.
- Download the latest version of
Android Command Line Tools Onlyfor Linux. This will download a .zip file. - You can use the following script to help you download and setup Android SDK and NDK(r25c) into your current working directory.
#!/bin/bash
shopt -s extglob
if [ -z "$1" ]
then
echo "Supply path to commandlinetools-linux-*_latest.zip"
exit 1
fi
android_sdk=$(pwd)/android_sdk
mkdir -p $android_sdk
unzip $1 -d $android_sdk
latest=$android_sdk/cmdline-tools/latest
mkdir -p $latest
mv $android_sdk/cmdline-tools/!(latest) $latest
$latest/bin/sdkmanager "ndk;25.2.9519653" "build-tools;33.0.2" "platforms;android-31" "platform-tools"
cp -avr $android_sdk/cmdline-tools/latest $android_sdk/tools
Simply run the script by giving it execution permission (chmod +x) and passing the path to the downloaded .zip file as a cli argument.
- Add the Android SDK and NDK paths into the following environment variables:
export ANDROID_SDK_ROOT=“/android_sdk”
export ANDROID_NDK_ROOT=“/android_sdk/ndk/25.2.9519653”
Step 2: Cross-compile Qt for Python wheels for Android
Python-for-android requires shiboken6 and PySide6 to be cross-compiled during the deployment process to produce Qt for Python binaries that are compatible with the specific Android platform. Cross-compiling Qt for Python every time for each of your applications can be a cumbersome, time-consuming task . Hence, it is better to use cross-compilation once to create Qt for Python wheels for an Android platform, which can be reused for each of the applications that you deploy. We have made creating these wheels easier for you with a Python script which is available in the Qt for Python source repository.
Make sure to install all the project requirements up to and including “Getting the source”, then install the cross-compilation requirements like this:
pip install –r tools/cross_compile_android/requirements.txt
And run the following script:
python tools/cross_compile_android/main.py --plat-name=aarch64 --ndk-path=$ANDROID_NDK_ROOT --qt-install-path=/opt/Qt/6.5.0 --sdk-path=$ANDROID_SDK_ROOT
In the above command, --plat-name refers to one of aarch64, armv7a, i686, x86_64 depending on the target architecture. --qt-install-path refers to the path where Qt 6.5.0 or later is installed. Use --help to see all the other available options.
After the successful completion of this command, you will have the Qt for Python wheels in pyside-setup/dist folder.
Note: We recommend using venv or virtuanenv
Step 3: Deploy your application - pyside6-android-deploy
For this tutorial, we take a simple QtQuick example Scene Graph Painted Item example. You can download this example directly from the link. One main requirement of pyside6-android-deploy tool is that the main Python entry point file should be named main.py. Change the name of painteditem.py to main.py and adjust correspondingly in painteditem.pyproject. The requirement of having the main Python entry point named main.py comes from python-for-android. Having the .pyproject file is not a strict requirement, but it enables pyside6-android-deploy to find the files associated with the project more easily and not include any unnecessary files.
Run the following command:
pyside6-android-deploy --wheel-pyside=pyside-setup/dist/PySide6-6.5.0a1-6.5.0-cp37-abi3-android_aarch64.whl --wheel-shiboken=pyside-setup/dist/shiboken6-6.5.0a1-6.5.0-cp37-abi3-android_aarch64.whl --name=painteditem
In the above command --name refers to the application’s name, as shown in your Android device. Use --help to see the other available options.
At the end of this command, you will have a .apk file created within the application directory, which you can install on your aarch64 based Android device. Hurray, you have successfully taken your Qt for Python application to Android.
Considerations
Presently, the tool
pyside6-android-deployonly works from Linux.
This limitation comes from our cross-compilation infrastructure that we are actively looking to improve and allow macOS and Windows users to also deploy Android applications.Qt modules supported:
QtCore,QtGui,QtWidgets,QtNetwork,QtOpenGL,QtQml, QtQuick, QtQuickControls2.The
mainPython entry point of the application should be namedmain.py
This requirement comes frompython-for-android.
What can you expect in the future?
More tutorials and examples
You can expect all the Qt for Android examples to also work and be available forPySide6Android deployment.Simplifying the current deployment process
There are some manual steps that we are aiming to remove, to allow the deployment of applications to be more straightforward.
4.Additional Qt modules compatibility
There are many examples and real use-case that our Qt for Android offering has, and we want to aim to be compatible with them. That’s why we see value in adding support for QtConcurrent, QtPositioning, QtLocation, QtBluetooth, QtSensors, etc.
Thank you for reading this tutorial. Have fun trying out PySide6 Android deployment. Feel free to drop us a message or open a suggestion/bug in JIRA. Your feedback fuels us in making Qt for Python better. Also, feel open to connecting to the Qt for Python community through our community platforms.
Stay tuned for further updates on Android deployment .
QT: qtpy 抽象的QT API 库 与 Qt for MCU + PyQt6 to Android的更多相关文章
- API Design Principles -- QT Project
[the original link] One of Qt’s most reputed merits is its consistent, easy-to-learn, powerfulAPI. T ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- Qt打开外部程序和文件夹需要注意的细节(Qt调用VC写的动态库,VC需要用C的方式输出函数,否则MinGW32编译过程会报错)
下午写程序中遇到几个小细节,需要在这里记录一下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 QProcess *process = new QProcess(this ...
- QT调用百度语音REST API实现语音合成
QT调用百度语音REST API实现语音合成 1.首先点击点击链接http://yuyin.baidu.com/docs/tts 点击access_token,获取access_token,里面有详细 ...
- Qt Widgets——抽象按钮及其继承类
QAbstractButton是有关“按钮”的基类 描述了一个按钮应该具有的组成.它的公有函数如下: QAbstractButton(QWidget * parent = ) ~QAbstractBu ...
- Qt多线程-QtConcurrent并行运算高级API
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QtConcurrent并行运算高级API 本文地址:http://tec ...
- Qt中加载Libevent静态库(通过reimp和rs两条语句将lib转为a)
文章来源:http://blog.sina.com.cn/s/blog_731bf4c90102wnpr.html 本文仅是个人经验总结,若有错误欢迎指教! 最近要做一个跨平台的项目,同时也涉及到网络 ...
- 【Linux开发】【Qt开发】配置tslibs触摸屏库环境设置调试对应的设备挂载点
[Linux开发][Qt开发]配置tslibs触摸屏库环境设置调试对应的设备挂载点 标签(空格分隔): [Linux开发] [Qt开发] 比如: cat /dev/input/mice cat /de ...
- 对Qt for Android的评价(很全面,基本已经没有问题了,网易战网客户端就是Qt quick写的),可以重用QT积累20年的RTL是好事,QML效率是HTML5的5倍
现在Qt不要光看跨平台了,Qt也有能力和原生应用进行较量的.可以直接去Qt官网查看他和那些厂商合作.关于和Java的比较,框架和Java进行比较似乎不且实际.如果是C++和Java比较,网上有很多文章 ...
- 加快QT工程编译速度(还可给Qt for Android设置)
一.多核编译 环境:win10, Qt 5.4.1,编译器mingw32 项目: Qt for Android Qt Creator 在编译android项目时不支持预编译,默认cpu单核编译,工程稍 ...
随机推荐
- 5.3K star!硅基生命新纪元,这个开源数字人框架要火!
嗨,大家好,我是小华同学,关注我们获得"最新.最全.最优质"开源项目和高效工作学习方法 "只需3分钟视频素材,就能打造专属数字分身!""开源免费商用, ...
- JSP (二) -- JSP与HTML集成开发
目录 脚本 普通脚本 声明脚本 输出脚本 JSP注释 语法规则 JSP指令 page指令 include指令 taglib指令 动作标签 include useBean setProperty get ...
- IO流-转换流、序列化流--java进阶day14
1.转换流 转换流本质还是字符流的子类 转换流的作用 1.可以按照指定的编码进行读写操作 我们使用的IO流,默认格式都是UTF-8,如果一个文件是GBK格式,在读写的时候就会乱码,此时就可以使用转换流 ...
- My Calendar III——LeetCode⑪
//原题链接https://leetcode.com/problems/my-calendar-iii/submissions/ 题目描述 Implement a MyCalendarThree cl ...
- java netty socket实例:报文长度+报文内容,springboot
前言 说实话,java netty方面的资料不算多,尤其是自定义报文格式的,少之又少 自己写了个简单的收发:报文长度+报文内容 发送的话,没有写自动组装格式,自己看需求吧,需要的话,自己完善 服务端启 ...
- update注入之我理解
1.基本语法 update test.test_table set username='admin123',password=000 where id=1; update test.test_tabl ...
- python基础—内置函数
1.数学运算类 (1).abs(x) 求绝对值,参数x可以是整形,也可也是复数,如果是复数,则返回复数的模 abs(-1) >> 1 (2).divmod(x,y) 返回两个数值的商和余数 ...
- 全面剖析PHP8新特性:JIT编译器如何推动网站性能革命
本文由 ChatMoney团队出品 在Web开发领域,提高网站的响应速度一直是开发者和企业所追求的目标.随着技术的不断进步,PHP8的发布为我们带来了一个全新的工具--JIT(Just-In-Time ...
- Golang基础笔记七之指针,值类型和引用类型
本文首发于公众号:Hunter后端 原文链接:Golang基础笔记七之指针,值类型和引用类型 本篇笔记介绍 Golang 里的指针,值类型与引用类型相关的概念,以下是本篇笔记目录: 指针 值类型与引用 ...
- .NET Core 微服务架构学习与实践系列文章目录
一.为啥要总结和收集这个系列? 2018年离开了原来的Team加入了新的Team,开始做Java微服务的开发工作,接触了Spring Boot, Spring Cloud等技术栈,对微服务这种架构有了 ...