简体   繁体   English

C++ Qt 在 Android 和 iOS 上的应用

[英]C++ Qt application on Android and iOS

As an experiment, I have a pure Qt C++ application (without QML) compiling (with cmake & ninja) and running on:作为实验,我有一个纯 Qt C++ 应用程序(没有 QML)编译(使用 cmake 和忍者)并运行:

  • Windows Windows
  • macOS苹果系统
  • Linux (ubuntu and centos/redhat) Linux(ubuntu 和 centos/redhat)
  • FreeBSD自由BSD

It uses basically QMainWindow, QGraphicsItem and QDialog, iostream and a few C++ containers and iterators.它基本上使用 QMainWindow、QGraphicsItem 和 QDialog、iostream 以及一些 C++ 容器和迭代器。

I am wondering if the port to Android is:我想知道 Android 的端口是否为:

  • possible可能的
  • easy or complex (if possible)简单或复杂(如果可能)
  • and if there are examples online如果网上有例子

The same with iOS.与 iOS 相同。

Technically, it's possible: It's easy to compile C++-Qt applications for both Android and iOS.从技术上讲,这是可能的:为 Android 和 iOS 编译 C++-Qt 应用程序很容易。 For iOS, you'll still need a Mac with Xcode.对于 iOS,您仍然需要配备 Xcode 的 Mac。 Deploying, debugging, and running the app is quite simple and seamless, too.部署、调试和运行应用程序也非常简单和无缝。

Practically, it's a horrible idea to try to port the GUI of a non-trivial desktop-application to mobile.实际上,尝试将非平凡桌面应用程序的 GUI 移植到移动设备是一个可怕的想法。 Graphical user interfaces designed to be used with a large screen, mouse and keyboard just don't work well on small touch screens.设计用于大屏幕、鼠标和键盘的图形用户界面在小触摸屏上无法正常工作。

Since you've mentioned QDialog : Some concepts work very differently on mobile compared to desktop.既然您提到了QDialog :与桌面相比,某些概念在移动设备上的工作方式非常不同。 Eg, Dialog is replaced by Activity and users usually don't deal with files.例如, DialogActivity取代,用户通常不处理文件。

You can (I've done it), however, design a Qt GUI-application without any QML, that works well on small touch screens and is at least usable on desktop.但是,您可以(我已经做到了)设计一个没有任何 QML 的 Qt GUI 应用程序,该应用程序在小型触摸屏上运行良好,并且至少可以在桌面上使用。 It requires a lot of manual tweaking and hacking, but It's possible.它需要大量的手动调整和破解,但这是可能的。

Notes:笔记:

  • qmake is easier than cmake for mobile apps (that should change in future) qmake对于移动应用程序比cmake更容易(将来应该会改变)
  • although Qt has some abstractions, you'll probably need some platform-specific code (ie, JNI , snippets of Java and Objective-C and many #ifdef s)尽管 Qt 有一些抽象,但您可能需要一些特定于平台的代码(即JNIJavaObjective-C的片段和许多#ifdef

Yes, it is possible.对的,这是可能的。 I have worked in many Qt apps developed for iOS and Android.我曾在许多为 iOS 和 Android 开发的 Qt 应用程序中工作过。 However, never used cmake, but qmake.但是,从来没有用过cmake,而是qmake。 it is good that you started experimenting using cmake which is the future as qmake is going to be deprecated sometime in the future.很高兴您开始使用 cmake 进行试验,因为 qmake 将在未来某个时候被弃用。 Qt's official documentation started adding cmake getting started tutorial. Qt官方文档开始添加cmake入门教程。

https://doc.qt.io/qt-5/cmake-manual.html https://doc.qt.io/qt-5/cmake-manual.html

I would like to suggest to use Qt Quick for GUI on mobile devices.我想建议在移动设备上使用 Qt Quick 作为 GUI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM