Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of Qt for Android Development

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "Qt for Android development case analysis". In daily operation, I believe many people have doubts about Qt for Android development case analysis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Qt for Android development case analysis". Next, please follow the editor to study!

The specific steps are as follows:

For video playback on 1.Android platform, only qml MediaPlayer can be used.

File:// must be added to the path of the control in 2.qml for example:

Image {source: "file:///mnt/usbhost1/Config/logo.png"}

3.Intermodulation between js + and js in qml.

QQuickView view; view.setSource (QUrl (QStringLiteral ("qrc:///qml/MainView.qml"); QObject* qmlObj = (QObject*) view.rootObject (); MainWnd * w=new MainWnd (object); / / expose C++ class for qml to call, alias mainWndClass view.engine ()-> rootContext ()-> setContextProperty (QLatin1String ("mainWndClass"), w); / / C++ calls js method / / parameter in qml must be converted to QVariant QMetaObject::invokeMethod (qmlObj, "showRight", Q_ARG (QVariant,1)) / / call the js method of the child item qmlPlayer = qmlObj- > findChild ("playerArea"); QMetaObject::invokeMethod (qmlPlayer, "setVideoFile", Q_ARG (QVariant,currentVideoFile)); / / MainView.qml Rectangle {anchors.fill: parent property int leftAreaWidth: this.width/5*4 property int rightAreaWidth: this.width/5 property int queueFontSize function showRight (isShow) {.. } Player {id:playerArea / / set objectName, you can only find it in C++ objectName: "playerArea" width: parent.width height: parent.height}}

4.C calls java Android api +

Create a directory under the project directory\ android\ src\ org\ rophie\ ProjectName\ JavaClass.java

Org\ rophie\ ProjectName is the package name package org.rophie.ProjectName of the java class.

If I call Android API to adjust the volume of the system

Package org.rophie.ProjectName; import org.qtproject.qt5.android.bindings.QtActivity; import android.widget.Toast; import android.media.AudioManager; import android.content.Context; public class JavaClass extends QtActivity {private static JavaClass AudioManager instance; private static AudioManager mAudioManager; public JavaClass () {/ / constructor must be m_instance = this;} public static void setVolume (int vol) {if (mAudioManager==null) {mAudioManager= (AudioManager) m_instance.getSystemService (Context.AUDIO_SERVICE) } mAudioManager.setStreamVolume (AudioManager.STREAM_MUSIC, vol, 0);}}

Call C++:

QAndroidJniObject::callStaticMethod ("org/rophie/ProjectName/JavaClass", "setVolume", "(I) V", 3); / / refer to QAndroidJniObject class for more information

5.BroadcastReceiver implements self-boot, just like Android

Public void onReceive (Context context, Intent intent) {. / / JavaClass is the java main class Intent intent2 = new Intent (context, JavaClass.class) that inherits QtActivity;. }

6. Call the third-party jar package, create a new directory libs under the same level directory of src, and copy .jar into it.

At this point, the study on "Qt for Android development case analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report