如何在qt6中使用我的类Java的静态方法
我有: myfile.java:
import android.net.Uri
import android.content.ContentResolver
import android.os.ParcelFileDescriptor
package org.qtproject.example.p2p; // what I need write here?
public class MyFile {
static int getFdFromString(ContentResolver cr, String suri) {
var uri = Uri(suri);
var fd = cr.openFileDescriptor(uri, "r");
var res = fd.getFd();
return res;
}
}
以及我的应用程序中的此代码:
qDebug("================================================================================================");
auto activity = QJniObject(QNativeInterface::QAndroidApplication::context());
QJniObject uriString = QJniObject::fromString(filename);
QJniObject contentResolver = activity.callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;");
jint fd = QJniObject::callStaticMethod<jint>("MyFile", // what I need to write without "MyFile"?
"getFdFromString",
"(Landroid/content/ContentResolver;Ljava/lang/String)I",
contentResolver.object<jobject>(), uriString.object<jobject>());
qDebug() << fd;
qDebug("================================================================================================");
如何连接此文件? (从QT(C ++)代码运行静态方法)
upd:好的...我不说我的项目结构: p2p/main.cpp,p2p/p2p.pro,p2p/...(我的应用程序的其他文件.cpp和.h)
在p2p/i中没有任何文件夹(如Android或...)。 我需要哪些文件夹创建并将“ myfile.java”移至他们?
UPD2:QT是我应用程序的起点。
i have:
MyFile.java:
import android.net.Uri
import android.content.ContentResolver
import android.os.ParcelFileDescriptor
package org.qtproject.example.p2p; // what I need write here?
public class MyFile {
static int getFdFromString(ContentResolver cr, String suri) {
var uri = Uri(suri);
var fd = cr.openFileDescriptor(uri, "r");
var res = fd.getFd();
return res;
}
}
and this code in my app:
qDebug("================================================================================================");
auto activity = QJniObject(QNativeInterface::QAndroidApplication::context());
QJniObject uriString = QJniObject::fromString(filename);
QJniObject contentResolver = activity.callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;");
jint fd = QJniObject::callStaticMethod<jint>("MyFile", // what I need to write without "MyFile"?
"getFdFromString",
"(Landroid/content/ContentResolver;Ljava/lang/String)I",
contentResolver.object<jobject>(), uriString.object<jobject>());
qDebug() << fd;
qDebug("================================================================================================");
How to connect this files? (run static method from Qt(c++) code)
Upd: ok... I don't say about my project struct:
p2p/main.cpp, p2p/p2p.pro, p2p/...(other files .cpp and .h of my app)
in p2p/ I don't have any folders(as android or ...).
What folders I need create and move "MyFile.java" to them?
Upd2: Qt is start point of my app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有帮助吗?
我认为您的Java课程的道路是
还释放了您的java文件,使该软件包成为文件中的第一行,然后来到imports
Does this help ?
I think the path to your java class is
Also correcet your java file , make the package the first line in your file , then come the imports