如何使用来自另一台 PC 的信息设置 QFileSystemModel? [英] How can I set a QFileSystemModel with information from another PC?

查看:62
本文介绍了如何使用来自另一台 PC 的信息设置 QFileSystemModel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个大学项目,我们需要在本地网络中设置类似 Dropbox 的服务.我可以在终端中轻松完成,但对于一些额外的点,我正在尝试为其设置 QtPy ui.

I'm doing a college project where we need to set up a dropbox-like service in a local network. I can do it easily in a terminal, but for some extra points I'm trying to set up an QtPy ui for it.

我的一个小部件是一个带有 QFileSystemModel 的 QTreeView,我想在其中可视化用户保存在他的保管箱"中的文件和文件夹.问题是,信息和文件夹本身在另一台计算机中.我试过将小部件从一台电脑发送到另一台电脑,但你不能腌制小部件.我也试过发送'self.model'并稍后添加,但它没有用.任何解决方案?这是小部件代码:

One of my widgets it's a QTreeView with a QFileSystemModel where I'd like to visualize the files and folders the user has saved on his "dropbox". The thing is, that the information and the folder itself are in another computer. I've tried sending the widget from one pc to another but you can't pickle widgets. I've also tried sending the 'self.model' and add it later but it didn't work. Any solutions? Here's the Widget Code:

class MyFolder(*form):

    def __init__(self):
        super().__init__()
        self.client = ""
        self.setupUi(self)
        self.model = QtGui.QFileSystemModel()
        self.model.setRootPath("./Archivos/MyFolder")
        self.myFolder.setModel(self.model)
        self.myFolder.setRootIndex(self.model.index("./Archivos/MyFolder"))
        self.addButton.clicked.connect(self.addDialog)

推荐答案

简短的回答是你不能直接这样做.如文档所述:

The short answer is you can't do that directly. As stated by the documentation:

QFileSystemModel 类为本地文件系统

The QFileSystemModel class provides a data model for the local filesystem

  • 另一方面,只要底层操作系统可以将远程文件系统表示为本地文件系统,QT 就可以将其显示为带有 QFileSystemModel 的本地文件系统.
  • 可以在本地表示的每个远程文件系统(使用 HTTP、(s)FTP、SMB(CIFS;Samba)、SSH 协议和可能的其他来源等协议),也可以表示为一个 QFileSystemModel.

    Every remote filesystem that can be represented locally (using protocols such as HTTP, (s)FTP, SMB (CIFS; Samba), SSH protocols and possible other sources), can also be represented in a QFileSystemModel.

    例如,在 Windows 上,您可以在专用驱动器号上挂载"远程文件系统(例如,通过使用 SMB 共享).在这种情况下,远程文件系统与本地文件系统完全相同,并且对于使用安装的本地驱动器的任何应用程序都是透明的.

    For instance on Windows you can "mount" a remote filesystem (for ex. by using using a SMB share) on a dedicated drive letter. In this case the remote filesystem is availabe exactly as a local one and it is transparent to any application using the mounted local drive.

    这篇关于如何使用来自另一台 PC 的信息设置 QFileSystemModel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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