使用 qt 浏览文件夹并将其文件添加到列表中

发布于 2024-10-02 20:32:15 字数 177 浏览 1 评论 0原文

你好,SO 很棒的社区!

我使用 qt 创建了一个 GUI 应用程序,并在主窗口中添加了一个 QTreeWidget 和 2 个按钮(添加和删除)。

是否可以找到代码示例来学习如何向此 QTreeWidget 添加和删除文件?

  • 我想在列表中显示它们的大小、名称和位置

Hello Great community of SO!

I have created a GUI application with qt and I added a QTreeWidget and a 2 buttons (add and delete) in my main window.

Is it possible to find examples of code in order to learn how to add and delete files to this QTreeWidget ?

  • I would like to display their size, name and location into the list

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠栀 2024-10-09 20:32:15

对于目录浏览,请尝试 QDir
要创建和删除文件,请使用 QFile
可以在 Qt 文档 中找到大量示例和教程。
只需选择您的版本即可。

For directory browsing try QDir.
To create and remove files use QFile.
Quite a lot of examples and tutorials can be found here Qt documentation.
Just select your release.

悍妇囚夫 2024-10-09 20:32:15

您看过 Qt 本身附带的演示吗?
我可以告诉你两个例子:

  1. 在 QtAssistant 中,转到 Qt 参考文档 -> 概述 -> 查看类,你就有了示例。

  2. 更详细:在 QtAssistant 中,转到:Qt 参考文档 -> 教程和示例:在 XQuery、XPath 下有文件系统示例。

添加文件可以像打开一个新文件(从用户那里获取文件名)并关闭它一样简单(我不知道你到底想要什么 - 相当于“touch”命令?)。

要删除,您可以调用: bool QDir::remove ( const QString & fileName )

Did you look at the demos that come bundled with Qt itself?
I can tell you of two examples:

  1. In QtAssistant, go to Qt Reference Documentation->Overviews->View Classes and you have your example.

  2. More elaborate: In QtAssistant, go to: Qt Reference Documentation->Tutorials and Examples: Under XQuery,XPath you have File System Example.

Adding file can be as simple as opening a new file (taking the filename from user) and closing it (I don't know what exactly you want here - some equivalent of "touch" command?).

For deleting, you can call: bool QDir::remove ( const QString & fileName )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文