Preview of Qt 5 for Android

Preview of Qt 5 for Android

Published March 13, 2013 | By  Eskil Abrahamsen Blomfeldt
The first commit in the effort to port Qt 4 to Android was on Christmas Day, 2009:  “Android mkspecs and semaphore”  by BogDan Vatra.
On January 22nd, 2010, he committed  “A small step for Qt, a giant leap for android”  with a working graphics system plugin and could actually run Qt applications on an Android device. He uploaded  a video  to celebrate.
On February 20th, 2011, he  announced  the first usable release of Qt 4 for Android, under the moniker of  Necessitas .
For the past 3+ years, BogDan and others have been (and are still)developing Necessitas on their spare-time, and on November 8th, lastyear, BogDan agreed to take his work into Qt 5 and  submit the port to the Qt Project .
He pushed the first version of Qt 5 for Android to a WIP branch onJanuary 4th, and recently we integrated into the “dev” branch, meaningthat it will become part of Qt 5.1 when it is released.
For this preliminary release, we are focusing on the developerexperience, working to enable Qt developers to easily run and test theirapplications on Android devices. While there’s nothing preventing youfrom deploying your app to an app store with Qt 5.1, we’re recommendingthat people wait until Qt 5.2 before they do that, as we’d like to putsome more work into improving that experience: Making more options forhow your app is deployed, adding more polish in general, and adding moresupport for Android APIs, both by allowing you to extend your app withJava code or by mapping them in  C++  APIs, whichever makes the mostsense.
On to the demos!
To start off, here’s a video of  the Qt 5 Cinematic Experience demo running on (from left to right): a Nexus 4, an Asus Transformer PadTF300T and a Nexus 7. The Cinematic Experience demo has quickly becomeour demo of choice at events, because it nicely shows a lot of the newgraphical capabilities in Qt Quick 2, such as shader effects, particleeffects, the new PathAnimation as well as the hardware-acceleratedSceneGraph architecture underneath, which makes it possible to run allthis at 60 fps.

In addition to the core parts of Qt, we also support the QML mediaplayer APIs in QtMultimedia. Here’s a nice video player written by Andyin QML, with fragment shader effects on top of the video, running on anAsus Transformer TF300:

To show off multi-touch support, here’s a simple hand painting demorunning on a Nexus 4. This also shows the support for native menus:

The lowest Android API level supported by Qt 5 is API level 10, akaAndroid version 2.3.3. This means we can also have Qt apps running onreasonably priced devices, such as this Huawei Y100:

Here’s the overview of what we have right now:
  • Support for creating Qt Widgets and Qt Quick apps that run on Android devices.
  • Support for Android API level 10 (version 2.3.3) and up.
  • QML media player functionality in QtMultimedia.
  • A set of commonly used sensors in QtSensors.
  • Cross-platform features of Qt of course (including Qt Quick controls and QtGraphicalEffects.)
  • Developing and configuring apps in Qt Creator 2.7.
  • Deploying a test build to a device directly from Qt Creator.

In addition, we plan to soon support the possibility of distributingthe Qt libraries through the Ministro distribution tool, which allowsyou to share a set of Qt libraries across several apps on a device, andwhich will be the primary way of deploying apps with Qt 5.1. Other thanthat, this is all already available: Just check out the  wiki forinstructions. Let us know if anything goes horribly wrong. We canusually be found in the #necessitas channel on the Freenode IRC servers.
What’s next, you ask? You can in fact help us decide! Both by  reporting your bug findings and feature expectations to us , and by  contributing your code . We will be working steadily on improving Qt 5 for Android, and would benefit greatly from your feedback. In the  wiki ,we are also compiling a list of devices where Qt has been verified torun. If you take the time to add devices you have tested to the listthere (as well as any issues you have found), it would very much beappreciated   
Finally: A big thanks to BogDan Vatra, Ray Donnelly and everyone elsewho has been contributing to the Necessitas project for the past years,as well as Qt 5 for Android in the past months. And thanks to everyonewho will contribute in the future.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Qt for Android中调用原生系统摄像头进行录像并保存输出,可以使用Android NDK来实现。下面是实现步骤: 1. 在Qt项目中添加一个Java文件,文件名为CameraRecorder.java,代码如下: ``` package com.example.myapplication; import android.hardware.Camera; import android.media.CamcorderProfile; import android.media.MediaRecorder; import android.os.Environment; import android.util.Log; import android.view.SurfaceHolder; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; public class CameraRecorder implements SurfaceHolder.Callback { private static final String TAG = "CameraRecorder"; private Camera mCamera; private MediaRecorder mMediaRecorder; private SurfaceHolder mHolder; private boolean mIsRecording = false; public CameraRecorder(SurfaceHolder holder) { mHolder = holder; mHolder.addCallback(this); } public void startRecording() { if (mCamera == null) { mCamera = getCameraInstance(); } try { mCamera.setPreviewDisplay(mHolder); mCamera.startPreview(); } catch (IOException e) { Log.e(TAG, "Error starting camera preview: " + e.getMessage()); } mMediaRecorder = new MediaRecorder(); mCamera.unlock(); mMediaRecorder.setCamera(mCamera); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); mMediaRecorder.setProfile(profile); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); String currentDateAndTime = dateFormat.format(new Date()); File mediaFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/", "VID_" + currentDateAndTime + ".mp4"); mMediaRecorder.setOutputFile(mediaFile.getAbsolutePath()); try { mMediaRecorder.prepare(); } catch (IOException e) { Log.e(TAG, "Error preparing media recorder: " + e.getMessage()); } mMediaRecorder.start(); mIsRecording = true; } public void stopRecording() { if (mIsRecording) { mMediaRecorder.stop(); mMediaRecorder.release(); mCamera.lock(); mCamera.release(); mCamera = null; mIsRecording = false; } } private Camera getCameraInstance() { Camera camera = null; try { camera = Camera.open(); } catch (Exception e) { Log.e(TAG, "Error opening camera: " + e.getMessage()); } if (camera != null) { Camera.Parameters params = camera.getParameters(); List<Camera.Size> sizes = params.getSupportedPreviewSizes(); Camera.Size size = sizes.get(0); params.setPreviewSize(size.width, size.height); camera.setParameters(params); } return camera; } @Override public void surfaceCreated(SurfaceHolder holder) { } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } @Override public void surfaceDestroyed(SurfaceHolder holder) { stopRecording(); } } ``` 2. 在Qt项目的AndroidManifest.xml文件中添加如下权限: ``` <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ``` 3. 在Qt项目中添加一个QML页面,页面中添加一个SurfaceView控件,并在控件上叠加一个按钮,代码如下: ``` import QtQuick 2.0 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.2 import QtQuick.Dialogs 1.2 import QtAndroidExtras 1.4 Rectangle { id: root width: 360 height: 640 color: "white" SurfaceView { id: surfaceView anchors.fill: parent } Button { id: btnRecorder text: "Start Recording" width: 200 height: 50 anchors.centerIn: parent onClicked: { if (btnRecorder.text === "Start Recording") { var recorder = QtAndroid.createQmlObject('import com.example.myapplication 1.0; CameraRecorder {id: recorder;}', surfaceView); recorder.startRecording(); btnRecorder.text = "Stop Recording"; } else { recorder.stopRecording(); btnRecorder.text = "Start Recording"; } } } } ``` 4. 编译并运行Qt项目,在页面中点击按钮即可开始录制视频。视频文件保存在SD卡的DCIM/Camera目录下。 以上代码仅为示例代码,具体实现可以根据自己的需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值