QT创建者 - 如何存储/将选定的文件存储到项目目录

发布于 2025-01-27 02:23:04 字数 667 浏览 3 评论 0原文

我正在尝试创建一种将文件存储在项目目录中的方法。我正在使用qfiledialog对话框,并使用qfile :: copy()来复制所选文件。我能够通过将其存储在项目目录(桌面)之外来使其工作。但是为此,我需要它存储在项目目录中。

如果需要,我很乐意提供其他信息。

注意:我也尝试将其存储在资源文件夹中而没有成功。顺便说一句,我是QT开发世界的新手。

QString filePath = QFileDialog::getOpenFileName(this, QObject::tr("PDF files"),
                                                "C:/", "PDF (*.pdf) ;; JPG (*.jpg) ;; PNG (*.png)");

QFileInfo file(filePath);
QString fileName= file.fileName();

if(QFile::copy(filePath, ":/PDF/PDF/"+fileName))
    qDebug() << "success";
else
    qDebug() << "FAILED TO LOAD TO -> :/PDF/PDF/"+fileName;

I am trying to create a way to store file's in the project directory. I am using QFileDialog for the dialog and using Qfile::copy() to copy the selected file. I was able to get it to work by storing it outside the project directory (Desktop). But for this, I need it to store in the project directory.

I am more than happy to provide additional information if needed.

Note: I tried storing it in the Resource folder as well without success. BTW, I am new to qt development world.

QString filePath = QFileDialog::getOpenFileName(this, QObject::tr("PDF files"),
                                                "C:/", "PDF (*.pdf) ;; JPG (*.jpg) ;; PNG (*.png)");

QFileInfo file(filePath);
QString fileName= file.fileName();

if(QFile::copy(filePath, ":/PDF/PDF/"+fileName))
    qDebug() << "success";
else
    qDebug() << "FAILED TO LOAD TO -> :/PDF/PDF/"+fileName;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文