As an experiment, I have a pure Qt C++ application (without QML) compiling (with cmake & ninja) and running on:
Windows
macOS
Linux (ubuntu and centos/redhat)
FreeBSD
It uses basically QMainWindow, QGraphicsItem and QDialog, iostream and a few C++ containers and iterators.
I am wondering if the port to Android is:
possible
easy or complex (if possible)
and if there are examples online
The same with iOS.
Yes, it is possible. I have worked in many Qt apps developed for iOS and Android. However, never used cmake, but 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. Qt's official documentation started adding cmake getting started tutorial.
https://doc.qt.io/qt-5/cmake-manual.html
I would like to suggest to use Qt Quick for GUI on mobile devices.
Technically, it's possible:
It's easy to compile C++-Qt applications for both Android and iOS.
For iOS, you'll still need a Mac with Xcode.
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.
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.
E.g., Dialog is replaced by Activity and users usually don't deal with files.
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.
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)
although Qt has some abstractions, you'll probably need some platform-specific code (i.e., JNI, snippets of Java and Objective-C and many #ifdefs)
Related
I am currently planning the development of a multiplatform app, and I am not sure wich way to do it fits my requirements best, since all possibilties I could think of failed to satisfy me.
First I want to write an app for android, which should feel like a normal typical android app. So I want to use the standard actionbar and android design look and feel in my other gui elements. After finishing the android app I am planning on developing an ios app, which should have a different design, so i am going to redevelop the gui for this anyway.
But I don´t want to rewrite the other code wich represents the intelligence of the app, independent from the gui. I came up with the following possibilities:
1. Java GUI With native library
Here I abstract all the code of my app in a C++ library (since as far as I know ios supports the usage of c++ libraries too) and develop the gui android typically in java. The library would than have a function to start and would inform the gui about every change via callback functions.
Pro
I can reuse all the code that would be the same on both platforms. I just would implement the gui seperately
The design of the android gui is straightforward as I want it to be. It looks like typical android because it is typical android.
Cons
I dislike the usage of JNI very much. Especially the signature and names of the callback functions (calling java functions from c++) are not checked at compile time and require a lot of manual work. If I rename a function and forget to rework the native part I only notice this mistake at runtime.
2. Build the GUI on the native side
Here I had difficulties finding out what is possible, especially for 2.2
2.1 Use Qt
I have only a few first step experiences with Qt in general but as far as I understood i would have the following pros and cons:
Pro
Reuse most parts of the code for ios and Android. I would than redesign the gui for each platform to make them feel natural. I can´t evaluate how much qt may even assists me at doing that
Cons
I have to copy the android gui by using other qt widgets. This is more effort and I don´t know if one can replicate the android gui elements (like the actionbar) so that the user wouldn´t notice it.
2.2 Using the android framework from the native side
I dont know if this is possible at all, I wasn´t able to find this information. Can I use the class "NativeActivity" and use the android framework to build the gui and use e.g. the actionbar? If this is possible somehow it would have the pros from 1. and maybe wouldn´t have it cons?
Do you have any feedback to my ideas or maybe even new approaches I didn´t think of? How do other multiplatform apps like WhatsApp solve this problem? Do they have redundant code for each platform?
Thank you,
Tobi
I would say that it depends very much on your application requirements. By my opinion, a better solution is to develop a separate application for each platform using recommended SDK's for that platform, and implement in native C++ only the time consuming data processing algorithms.
Application runtime on mobile platforms is not so straightforward as on desktop platforms. You should take into account background and foreground processing, specific application life cycling, accessing system resources such as network, file system, etc. And all these issues do differ on iOS and Android.
Regarding possibilities that you listed.
Qt/QML is ok only in case two requirements are met:
1.1 Your application is a foregroud application without any background operations.
1.2 You purchase a commercial Qt license because only commercial Qt can be submitted to Apple iTunes app store (even GPL apps are under
question).
Using NDK Native Activities on Android with cross-platform C/C++ backend. Android NDK API offers much less API then Android Java SDK, so a lot of things you will have to implement or wrap manually. It is a hard road.
Mixing Java code and C/C++ using JNI gives you more of Android SDK API. But you should remember that an Android activity's life cycle is not somewhat that you're used to deal with when developing on C/C++.
Approach that we are using
We've been developing an application with a huge amount of cross platform functionality that should work on Windows/Linux/Mac OSx/Android/iOS. We're using the approach as follows.
Cross-platform core is written in pure C++.
We have adaptors to GUI interface for each platform.
On desktop we use Qt as it reaches all desktop platforms with minor adapting to each platform.
On iOS the GUI is built using iOS SDK with Objective-C and C++ core is linked as a Framework. Still, we had to patch our core in some way for iOS background requirements and so.
On Android we wrap our C++ core in a background process and build all the GUI using only Android Java SDK. Foreground GUI activities interact with the core via local sockets, so we don't need to bother with activities life cycling in our C++ core. But the adaptor is a litle bit complicated.
Nevertheless, both mobile platforms often require workarounds and adaptations in C++ core which add a number of #ifdef'ed branches in code for each platform.
Well I've been coding in qt for about 6 months now and I have a pretty good grasp of QWidget and c++ coding for desktop apps but I run a small company and we are developing phone apps and desktop apps for a project that we are doing and as the project manager I fell that qt is the answer for not having to have separate teams coding for android and iPhone.
So the solution is coding in qt. but I'm a little confused about a few things. I see that a lot of the event handling of button clicks and things are handled actually in qt quick but as our apps would be quite complex in the bg we would have to be able to code in c++ the QWidget conventional way. So my question is:
Which is better QWidget or Qt quick better for developing our apps which should be compatible across most platforms, mostly tablet and smart phones.
If we go the qt Quick way then can you simultaneously use qt quick for most of the visual and then link up these files to c++ files (the engine of your app)? m if so any examples of how I might get started on learning how to do this.
Is there any really good resources on how to develop these phone apps, tutorials and things like that, as I'm a little worried about the lack of resources for learning.
Am I correct in thinking that if we did go with qt quick that these apps would also be compatible with Ubuntu phone?
I've developed applications for maemo and meego, and I'd say that QtQuick is better and much easier.
I'd say that QML and C++ qt-backend introduces an MVC pattern where QML is View and C++ is model and controller. QML is not just a script you can run. You need an object of QDeclarativeScript in C++ and pass main qml file to it to be able to start. So, anyway you will run C++ application first, which will parse QML script. To the last part of question: you may create C++ classes to export into QML and use it there. It is very simple, you may read official guides of QtQuick, it is goodly explained there.
Here is nothing special. Simply import files into qml-project and just use controls, containers and etc. Each project, be it ubuntu phone or sailfish, have a tutorials, guides and wiki. More, I'm KDE contributor and developed plasma widgets on QML - the same thing here, - all you need is to import and just use.
Of course. Why not? But you need to have a toolchain for QtCreator to be able to compile your project for target architecture and be able to run it there.
I have game (of cards based on Contract Bridge) written in Qt (QML) for KDE, now I'm supposed to port the entire game to Android (with Android apapted UI of course). At first I considered to use Necessitas (a Qt port for Android) but found that it is still under development and is currently in 3rd Alpha. I'm new to Android development (as well as game development), while I have experience working in Java, C++ and web technologies like HTML5, JavaScript.
Hence based on my skills, I considered using MoSync. But I'm not sure if I'll be able to use any existing modules of game already developed in Qt (while in MoSync its possible to invoke C++ code from JavaScript and vice-versa), and since I didn't worked on the Qt version of the game, I'll first have to refer to that code and then I'll be working on Android version of the same. So I need suggestion that from where should I start. Also, I have 1.5 months of duration to complete the project (without any working hour constraints), so also suggest me if its a good idea to work from scratch using Android APIs.
Please let me know if I need to elaborate the question even further.
Thanks.
I recommend taking a look at V-Play (v-play.net). It's a cross platform game engine based on Qt/QML .
If your game is already written in QML, you have the least porting effort because you can use almost all of your existing code, and use V-Play QML game components for handling multiple display resolutions & aspect ratios, animations, particles, physics, multi-touch, gestures, path finding and more (API reference).
You can also take a look at Benefits to find out if V-Play satisfies your demands.
Qt is more cross-platform than ever now. instead of porting, just modify it a little and continue with Qt, then compile for iOS, Android, etc.
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch is one of the great HTML 5 Web App Kit.
I know a little about both of them however i made a very small application using MonoTouch for iPad, certainly MonoTouch (and particularly with supporting XCode) is awesome. But i did not tried SenchaTouch
The advantage of using MonoTouch is that you can write c#; consequently i really enjoy it owing to the fact that i am a c# developer; In contrast a disadvantage of SenchaTouch for me is Java language and i really did not find any IDE like visual studio or xcode to Drag&Drop UI(s) and it generate the Xml Code
Many are in this view that on account of the fact that MonoTouch is a Cross-Compiler; Consequently the applications developed by MonoTouch is not as fast as others like SenchaTouch .
I am really looking for a good advise from you,
Your advise is welcome here.
Regards,
S. Peyman Mortazavi
Monotouch is not a cross-compiler, and even if it were that alone would not cause a performance penalty.
Monotouch is a .Net compatible runtime that runs on iOS embedded within a normal c/obj-c program. It includes bindings for more or less the same things you can do from normal iOS apps. Monotouch apps are AOT compiled rather than JIT compiled so in most cases they run just as fast as "normal apps"
The fact that SenchaTouch is a javascript framework suggests to me that you will be running mainly interpretted code. I'm sure the Sencha people have done a good job but I would be suprised if it were faster than mono. Looking at Sencha, one advantage is that you can write for android, blackberry and iOS. You can share much of your code between MonoTouch and Mono for Android, you need two licenses and can't share everything.
Don't forget that with the upcoming Windows Phone, you will be able to support this platform as well if you use C# - you will be able to re-use you libraries the contain the shared code.
I've been working on a game engine runtime environment in C++ for my future games, and have started to consider android as a platform. I noticed that it was tightly bound to Java and uses Java VMs heavily.
But is it possible to sustain a full C++ runtime environment in Android NDK? I have nothing against Java and am prepared to use it if I have to, but performance is one of my prime concerns (I intend for my games to be resource-intensive), especially on phones.
And if a full C++ environment is possible, how exactly would I implement it in Eclipse Indigo CDT? Would I be able to create a compiled game executable for Android ahead of time for maximum performance? And would there be any additional plugins I'd need to install in Eclipse? Could I use MinGW for compiling my games, or would I need to use a different compiler? If I had to use Java in one way or another, would compilation of the C++ code even be required? These are all questions I'd like to answer to get a sturdy development environment going in the Eclipse IDE.
Please know that I'm still fairly new to Android development, and multiplatform programming in general. My goal is to create a game engine that'll take the most advantage of the new hardware out there, especially on phones!
Thanks for any advice you guys can give!
NativeActivity, added in Android 2.3 (API 9) might be what you're looking for in terms of writing Android games using only C++. http://developer.android.com/reference/android/app/NativeActivity.html
However since you say you're new to this you may want to start with one of the currently available Android game engines instead of writing your own right away. Mobile devices have a very different set of constraints than other platforms. A phone isn't very useful if the battery dies mid-afternoon, so starting a project with the stated goal of being "resource-intensive" is already getting off to a bad start. Few people will want to play your games for 20 minutes here and there if it means they won't be able to make a phone call in the evening.
If what you meant is that you are shooting for high-end graphics, keep in mind that devices have a wide range of capability in this area and targeting only the high end limits your audience. Different GPUs have very different strategies and performance characteristics and all have cases where they shine or lag behind. The most successful mobile games aren't the ones with the highest polycounts or the most complex lighting shaders, they're the games that achieve a consistently smooth framerate and have a distinctive style.
Have a look at some of the existing game engines for Android and try them out. Write a couple small games to take them for a test drive and see where they do and don't mesh with what you're trying to do. If you find yourself feeling limited with what's available, take what you've learned and try to write your own engine that fits with the types of games you want to make.
Here are some links to get you started. These engines power some very popular games on Android Market and many developers have found them useful:
http://www.andengine.org/ andengine is written in Java and is open source.
http://unity3d.com/ Unity is based on C# and Mono.
http://www.madewithmarmalade.com/ Marmalade, formerly Airplay SDK is based on C++.
The answer you want to pay close attention to is #adamp's. Ignore his answer at your own peril.
To address a couple of other points in your question, though:
Would I be able to create a compiled game executable for Android ahead of time for maximum performance?
No, insofar as Android does not use "compiled game executables". Your C/C++ code will be compiled into a Linux shared object (.so) file and packaged with other stuff (like your manifest) in an APK file. Compiling the .so will be ahead of time, though.
Could I use MinGW for compiling my games would I need to use a different compiler?
I get the distinct impression that you will claw your eyes out trying to do NDK development in Cygwin on Windows. I heartily encourage you to do your NDK development on OS X or Linux. At least set up a VirtualBox with Ubuntu or something in it to do your NDK compiles.
Regardless, the NDK comes with its own GCC compiler. AFAIK, MinGW is not a cross-compiler, and most Android devices are not running on x86 CPUs.
If I had to use Java in one way or another, would compilation of the C++ code even be required?
Yes. Now, for Honeycomb, you have the option of using Renderscript for OpenGL work -- that amounts to a C99 environment whose code you will not need to compile with the NDK.
I've tried a bunch of them, and one of the best I found that cross compiles instantly to a bunch of other devices and let's you program your goodies in HTML5/C++ combo (sweeeeet) is MoSync (http://www.mosync.com/) and another little known one that is a little more setup friendly is MotoDev by Motorola (http://developer.motorola.com/tools/motodevstudio/?utm_campaign=mhp01092012&utm_source=mhp&utm_medium=mws)
I've noticed there is some virtual machine images and tutorials you can use to prevent the setting up hassle.