我正在编写一个应用程序,它要求我使用另一个文件系统和文件引擎处理程序,而不是 qt 的默认处理程序。基本上我想要做的是使用 qt 的文件对话框,但有一个底层文件系统处理程序(例如使用 boost 文件系统库构建),处理与该对话框中的文件和目录操作有关的所有操作。我已经编写了一个自定义文件引擎来处理一些操作,但我现在陷入了 Qt 的文件系统模型和文件系统观察器引擎的困境,因为我需要为这个自定义文件引擎传输信号。看来我前面有一项艰巨的任务。我正朝着正确的方向前进吗?
还有其他更简单的方法可以实现这个吗?谁能给我任何关于如何继续的想法。我正在考虑研究代理模型,但不确定这是否可行。
预先感谢您的任何帮助。
I am writing an application which requires me to use another file system and file engine handlers and not the qt's default ones. Basically what I want to be able to do is to use qt's file dialog but have an underlying file system handler (for example built using boost file system library) of mine handling all the operations with regards to file and directory operations within that dialog. I have already written a custom file engine which handles some of the operations but I am now stuck with Qt's file system model and the file system watcher engine, as I need to have the signals transmitted for this custom file engine. Seems like I have a daunting task ahead. Am I heading in the right direction?
Is there any other simpler way that I could implement this? Can anyone give me any idea on how to proceed. I was thinking of looking into proxy models but not sure if that would work.
Thanks in advance for any help.
发布评论
评论(2)
代理模型使用底层模型包含的数据进行操作,因此,您不能使用它来获取全新的模型内容。
执行此类任务的明显方法是调查 QFileDialog 有什么样的模型,然后替换该模型。
当然,您可以从 QFileDialog 复制模型,相对于您的新文件引擎,然后以一种有点奇怪的方式使用 propxy 模型:设置它(它将连接到 QFileDialog 的底层模型,您无法访问另一种方式),然后使用代理的 setSourceModel() 来设置模型。
或者您只需获取 QFileDialog 的代码并用您的代码替换文件系统感知的代码。但我认为它闻起来很糟糕,而且我不知道它是否合法以及由于许可证等原因您可能会面临哪些问题。
Proxy model operates with data, that underlying model contains, so, you can't use it to get entirely new model contents.
The obvious way to do such tasks is to investigate, what kind of model QFileDialog has, and then replace the model.
You can, probably, copy the model from QFileDialog, with respect to your new file engine, of course, and then use propxy model in a somewhat strange way: set it (it will connect to underlying model of QFileDialog, you can't access another way) and then use your proxy's setSourceModel() to set your model instead.
Or you simply can get the code of QFileDialog and replace filesystem-awared code with yours. But it smells bad, I think, and I don't know if it legal and what issues you can face due to the licences and so one.
过去可以使用 QAbstractFileEngine 等来做到这一点,但 Qt 4.6 中对 QDir 的更改在某种程度上破坏了它 - 请参阅 Qt bug 10333 根据我的经验。
It used to be possible to do this with QAbstractFileEngine etc. but the changes to QDir in Qt 4.6 broke it somewhat - see Qt bug 10333 for my experiences.