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单核编译,工程稍 ...
随机推荐
- Windows系统常用端口详解
7,9,13,17,19 这是几个简单的TCP/IP服务,在windows中被Simple TCP/IP Services管理. 7 : Echo 服务:将接收到的数据原样返回. 9 : Discar ...
- 如何使用 websocket 完成 socks5 网络穿透
有盆友好奇所谓的网络穿透是怎么做的 然后talk is cheap,please show code 所以只好写个简单且常见的websocket例子, 这里的例子大致是这个原理 浏览器插件(或者其他) ...
- K8s进阶之外部访问Pod的几种方式
概述 K8s集群内部的Pod默认是不对外提供访问,只能在集群内部进行访问.这样做是为什么呢? 安全性考虑 Kubernetes设计时遵循最小权限原则,即组件仅获得完成其任务所需的最少权限.直接暴露Po ...
- MSDN I tell you下载方式
1.复制下载链接 2. 去下载软件粘贴即可 下以百度网盘为例:
- AD 侦查-AS-REP 烘烤攻击
本文通过 Google 翻译 AD Recon – AS-REP Roasting Attacks 这篇文章所产生,本人仅是对机器翻译中部分表达别扭的字词进行了校正及个别注释补充. 导航 0 前言 1 ...
- algolia使用配置教程-为SSG静态站增加algolia搜索功能
要构建SSG静态站点时,一般为了方便增加algolia搜索框,但这里algolia配置使用时用很多的坑,折腾了我好几天,网上没有一个可用的教程. 自己弄了几天,终于搞明白里面的道道了,现在分享出来给大 ...
- 第5讲、Transformer 编码器(Encoder)处理过程详解
Transformer 编码器(Encoder)处理过程详解 Transformer Encoder 是一个由 N 层(一般为 6 层)堆叠而成的模块结构.每一层的本质是两个核心子模块: 多头自注意力 ...
- 面试题-Thread.sleep(0)的作用是什么
就是线程等待的意思.由于Java采用抢占式的线程调度算法,因此可能会出现某条线程常常获取到CPU控制权的情况,为了让某些优先级比较低的线程也能获取到CPU控制权,可以使用Thread.sleep( ...
- CentOS 7 系统调优深度指南
从内核参数.资源分配.存储性能到网络优化,覆盖全维度调优策略,并强调稳定性保障. 一.调优核心维度与操作命令 1. 内核参数调优 (/etc/sysctl.conf) bash # 编辑配置文件 vi ...
- 一种更简单的方式运行 C# 代码,简化 C# 开发体验!
前言 前段时间 .NET 10 Preview 4 推出了一种更简单的方式运行 C# 代码,即可以直接使用dotnet run file.cs 命令运行 C# 文件.这意味着我们不再需要创建项目文件或 ...