用 QML 编写文件管理器 [英] Writing a file manager in QML

查看:98
本文介绍了用 QML 编写文件管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 QML,之前没有 Qt 或 GUI 开发方面的经验.我的第一个任务是编写一个文件管理器.到目前为止,我喜欢 QML 的一点是我可以用纯文本进行设计,但它已经相当 具有挑战性 寻找方法来实现甚至是简单的事情.目前我使用 Qt.labs.FolderListModel 2.1 作为目录列表的工作马,我什至还没有接触过 C++ 或 PyQt,现在它是纯粹的 QML.

I just started learning QML, with no previous experience in Qt or GUI development in general. My first task is to write a file manager. So far what I like about QML is that I can do design in plain text, but it's been quite challenging finding the way around to achieve even simple things. Currently I use Qt.labs.FolderListModel 2.1 as the work horse for directory listing, and I haven't even touched C++ or PyQt yet, it's purely QML now.

所以我有几个关于我的小文件管理器未来路径的问题:

So I have a few questions regarding the future path of my little file manager:

  1. FolderListModel 是否足够强大,可以做所有事情万能的文件管理器能做什么?就我所见,QFileSystemModel 看起来功能更完整?而事实前者在 Qt.labs 中让我有点担心.如果确实FolderListModel 旨在用作快速而肮脏"的东西,这是否意味着最好切换到 QFileSystemModel早点?因为我是从 QML 而不是从传统C++角度,取代我现在的感觉怎么样FolderListModel QML 中的代码到 Qt/C++ 或 PyQt 支持的东西?
  2. 相关:我听说实际上可以用纯 QML(使用 JavaScript)编写完整的应用程序.如果应用程序由某个后端驱动,例如一个数据库,我可以看到仅 QML 可能不够表达.但是,在我编写文件管理器的情况下,尽管存在性能"论点,但尝试坚持纯 QML、将 JavaScript 用于所有业务逻辑是否是个好主意?
  1. Is FolderListModel powerful enough to do all the things a versatile file manager can do? As far as I see, QFileSystemModel looks more feature complete? And the fact that the former is in Qt.labs worries me a bit. If indeed FolderListModel is meant to be used as a "quick-and-dirty" thing, does that mean that it's better to switch to QFileSystemModel sooner? Since I approached the Qt world from QML rather than the traditional C++ angle, what is it like to replace my current FolderListModel code in QML to something backed by Qt/C++ or PyQt?
  2. Related: I heard that it's actually possible to write complete applications in pure QML (with JavaScript). If the application is driven by some back-end, e.g. a database, I can see that QML alone is probably not expressive enough. However, in my case of writing a file manager, despite the "performance" argument, is it a good idea to try to stick to pure QML, using JavaScript for all the business logic?

推荐答案

我最近一直在研究 QML 中的一个简单文件管理器.如果你只坚持 QML,你将面临的问题是:

I have been working recently on a simple file manager in QML. The problems you will face if you stick only to QML are:

  • 无法知道当前插入了多少驱动器.
  • 无法轻松地按名称对文件进行排序.由于这种情况,使用提供的排序标志将导致 B.txta.txt 之前.
  • not being able to know how many drives are currently plugged in.
  • not being able to easily sort files by name. Using provided sorting flags will result in having B.txt before a.txt because of the case.

幸运的是,将 C++ 类与 QML 连接起来很容易,因此您将始终能够扩展默认的 QML 功能.

Fortunately it is easy to connect C++ classes with QML so you will always be able to expand default QML features.

如何连接C++和QML:http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

How to connect C++ and QML: http://doc.qt.io/qt-5/qtqml-cppintegration-topic.html

这篇关于用 QML 编写文件管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆