qt iOS app 如何获取共享文件夹文件,如何使用document文档目录文件

how to get sharing document directory is something different with other qt platforms.

IOS app always use files only in app's sandbox. So we just need to find it's sandbox directory.

we may think following would work:

QString docPath;
    QDir dir;
    docPath=dir.currentPath();
    
however in qt 5.5 IOS, it return only root directory "/",

then we use another way:

docPath=QCoreApplication::applicationDirPath();

result is "/private/var/mobile/Containers/Bundle/Application/D31978DF-1A05-4AB9-9C36-18EA2B9E5294/testXXX.app",

is that the real sandbox directory? The answer is still no, because we can not show any files sync-in iPhone to testXXX app by iTunes.

(in qt .pro file,  we add lines

QMAKE_INFO_PLIST += aaa.plist

in aaa.plist we add "UIFileSharingEnabled true" to enable file sharing with iTunes.)

We have no patience to find other qt traditional way to solve this problem. We use mix IOS obj-c and qt c++ as follows:


QString iOSObj::getDocDir(void)
{
    iOSObj::g_iOSObj = this;
    //get Documents path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
NSLog(@"path:%@",path);
    QString temp = QString::fromNSString(path);
    return temp;
}

Finally, the result is

“/var/mobile/Containers/Data/Application/BB26B5E6-3340-4601-A81B-DE5362B1C938/Documents”







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt中,可以使用QFile和QIODevice类来实现文件的上传功能。下面是一个简单的示例代码,演示如何将文件上传到共享文件夹: ```cpp #include <Q> #include <Q> #include <QNetworkAccessManager> #include <QNetworkRequest> #include <QNetworkReply> void uploadFileToSharedFolder QString& filePath, const QUrl& sharedFolderUrl) { QFile file(filePath); if (!file.open(QIODevice::)) { qDebug() << "Failed to file for reading:" << file.errorString(); return; } NetworkAccessManager manager; QNetworkRequest requestFolderUrl); QNetworkReply* reply = manager.put(request, &file); QObject::connect(reply, &QNetworkReply::finished, [&]() { if (reply->error() == QNetworkReply::NoError) { qDebug() << "File uploaded successfully!"; } else { qDebug() << "Failed to upload file:" << reply->errorString(); } reply->deleteLater(); file.close(); }); } int main() { QString filePath = "path/to/your/file.txt"; QUrl sharedFolderUrl("smb://example.com/shared_folder"); uploadFileToSharedFolder(filePath, sharedFolderUrl); return 0; } ``` 上述代码中,首先使用QFile打开要上传的文件,然后创建一个QNetworkAccessManager对象来处理网络请求。接下来,创建一个QNetworkRequest对象,并将共享文件夹的URL作为参数传递给它。然后,使用QNetworkAccessManager的put方法将文件内容发送到共享文件夹。最后,通过连接QNetworkReply的finished信号来处理上传结果。 请注意,上述示例代码中使用的是SMB协议(smb://),你需要根据实际情况修改sharedFolderUrl的值,确保它指向正确的共享文件夹

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值