当前位置: 首页 > news >正文

广东东莞邮政编码成都排名seo公司

广东东莞邮政编码,成都排名seo公司,网站建设 400电话 广告,大公司网页设计用什么软件好一、前言 需求: Qt开发Android程序过程中,点击按钮就打开一个PPT文件。 Qt在Windows上要打开PPT文件或者其他文件很容易。可以使用QDesktopServices打开文件,非常方便。QDesktopServices提供了静态接口调用系统级别的功能。 这里用的QDesk…

一、前言

需求: Qt开发Android程序过程中,点击按钮就打开一个PPT文件。

Qt在Windows上要打开PPT文件或者其他文件很容易。可以使用QDesktopServices打开文件,非常方便。QDesktopServices提供了静态接口调用系统级别的功能。

这里用的QDesktopServices 是 Qt 框架中的一个类,用于在跨平台应用程序中方便地访问和使用主机操作系统的桌面服务和功能。该类提供了一些静态方法,用于打开网址、文件和邮件客户端等系统默认应用程序。它的主要目的是让开发者能够轻松调用系统级别的功能,而不需要直接编写与操作系统相关的代码。

代码如下:

QUrl url =  QUrl::fromLocalFile("storage/emulated/0/Download/UseHelp.ppt"); 
bool IsOK = QDesktopServices::openUrl(url);   

下面是QDesktopServices 的帮助文档介绍。

image-20240809101024234

QDesktopServices 只适用于桌面应用程序。 如果在Linux系统下想要打开PPT文件,也可以采用QDesktopServices 来实现。

前提也是需要先安装LibreOfficeOpenOffice才可以。

在Qt的文档里也提供了openUrl静态方法的使用说明。

image-20240809101206462

使用 QDesktopServices::openUrl在Linux系统上打开PPT文件。

#include <QDesktopServices>
#include <QUrl>
#include <QDebug>
​
int main(int argc, char *argv[])
{QApplication app(argc, argv);
​QString pptFilePath = "/path/to/your/presentation.ppt";QUrl pptUrl = QUrl::fromLocalFile(pptFilePath);
​if (!QDesktopServices::openUrl(pptUrl)) {qWarning() << "Failed to open PPT file.";}
​return app.exec();
}

但是在Android移动平台上,这个办法就行不通了。 需要通过JNI接口与Android系统交互,才可以完成系统级别的操作。

image-20240809100537433

二、通过JNI与Android系统交互

在Qt for Android中,可以通过Qt提供的Java Native Interface (JNI)与Android系统交互,可以调用系统功能,打开PPT文件。

下面演示如何在Qt中使用C++代码,通过JNI调用Android的Intent来打开PPT文件。

2.1 操作步骤

  1. 在Qt项目中添加Android相关的权限和活动声明

    • AndroidManifest.xml文件中添加必要的权限和活动声明。

  2. 使用Qt的JNI接口调用Android Intent

    • 在C++代码中使用Qt的JNI接口来调用Android的Intent。

2.2 代码

(1)AndroidManifest.xml

AndroidManifest.xml文件中添加以下权限声明,确保应用有权读取文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="org.qtproject.example"><application android:label="@string/app_name"><activity android:name="org.qtproject.qt5.android.bindings.QtActivity"android:configChanges="orientation|screenSize"android:label="@string/app_name"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>

(2)Qt C++代码

在Qt C++代码中使用JNI接口调用Android的Intent来打开PPT文件。

#include <QCoreApplication>
#include <QAndroidJniObject>
#include <QtAndroid>
#include <QDebug>
​
void openPPTFile(const QString &filePath) {QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");if (activity.isValid()) {QAndroidJniObject intent("android/content/Intent", "()V");intent.callObjectMethod("setAction", "(Ljava/lang/String;)Landroid/content/Intent;", QAndroidJniObject::fromString("android.intent.action.VIEW").object<jstring>());
​QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri","parse","(Ljava/lang/String;)Landroid/net/Uri;",QAndroidJniObject::fromString(filePath).object<jstring>());
​intent.callObjectMethod("setDataAndType", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;", uri.object<jobject>(), QAndroidJniObject::fromString("application/vnd.ms-powerpoint").object<jstring>());intent.callObjectMethod("addFlags", "(I)Landroid/content/Intent;", 0x10000000); // Intent.FLAG_ACTIVITY_NEW_TASKactivity.callMethod<void>("startActivity", "(Landroid/content/Intent;)V", intent.object<jobject>());} else {qDebug() << "Failed to get the activity.";}
}
​
int main(int argc, char *argv[])
{QCoreApplication app(argc, argv);
​QString pptFilePath = "/sdcard/Download/sample.pptx"; // 指定要打开的PPT文件路径openPPTFile(pptFilePath);
​return app.exec();
}

2.3 代码说明

  1. openPPTFile函数:该函数接受PPT文件的路径作为参数,并使用JNI接口调用Android的Intent来打开该文件。

  2. QAndroidJniObject:用于与Java对象和方法交互。

  3. setActionsetDataAndType方法:设置Intent的操作和数据类型。

  4. startActivity方法:启动Intent以打开PPT文件。

2.4 编译和运行

需要先在Android设备上安装合适的PPT查看应用(比如:WPS),并且PPT文件路径正确。编译和运行Qt项目时,应用将通过系统默认的应用打开指定的PPT文件。

http://www.yidumall.com/news/86025.html

相关文章:

  • 郑州网站建设专业公司青岛网站建设优化
  • 地板网站模板集团网站推广
  • 做国际生意的网站有哪些网站统计哪个好用
  • 专门做牛肉的网站竞价排名是按照什么来计费的
  • 做影视网站被告怎么办线上运营推广方案
  • 做诚信通网站百家号关键词seo优化
  • 易语言怎么做网页网站最简单的营销方案
  • wordpress 目录插件合肥网站优化公司
  • 网站的更新与维护google图片搜索引擎入口
  • 最佳网站线上商城的推广方案
  • 专业的移动网站建设公司排名企业微信管理系统
  • 公司域名是什么意思唐山seo
  • 网站建设mvc三层框架图希爱力
  • 网站链接做app产品优化是什么意思
  • 做网站公司 陕西渭南网站排名优化价格
  • 兰州企业网站网络推广公司收费标准
  • 做动画的网站有哪些宁波seo超级外链工具
  • 手机网站制作电话河南做网站优化
  • 房地产销售年终总结厦门网站快速排名优化
  • 管理网站建设源代码程序属于免费的网络营销方式
  • 江苏城乡建设学院网站seo和sem是什么意思啊
  • 网站目录权限设置今日头条权重查询
  • 微信做网站代购网络广告营销对应案例
  • 网站建设创意公司seo主要优化
  • 凡科网建站怎么样国内网络推广渠道
  • wordpress 分类合并网站搜索引擎优化工具
  • 舟山做网站谷歌seo搜索引擎下载
  • 大连网站制作.net购物网站有哪些
  • 手机企业网站正规seo排名公司
  • 物流企业网站建设福州短视频seo网站